0

Here's a sample for Android. The same thing happened when I tried it in desktop Java. How do I get it to work?

The prefix comes from another question about displaying UTF-8 in WebViews.

public class MainActivity extends Activity
{
    Util util = Util.get(this);

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        WebView w = new WebView(this);
        setContentView(w);
        String prefix = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
        String data0 = "%92";
        String data;
        try
        {
            data = URLDecoder.decode(data0, "UTF-8");
        }
        catch (UnsupportedEncodingException e)
        {
            data = e.getLocalizedMessage();
        }
        w.loadData(prefix + data, "text/html; charset=UTF-8", "utf-8");
    }
}
Tiiba
  • 67
  • 5

1 Answers1

0

The url-encoded octet-string %92 is not a valid UTF-8-encoded character string. It is valid in Windows-1252, though; there it corresponds to the curly right single quote, . Maybe you should be using "cp1252" instead of "UTF-8"?

If you want to use UTF-8, the curly right single quote should be URL-encoded as %E2%80%99.

Joni
  • 108,737
  • 14
  • 143
  • 193