0

Does anybody have similar problem when using a WebView to render app's content? It seem that '#' is not working well in recently update.

public class MainActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WebView webView = findViewById(R.id.webView);
    String html = "<html><body>This is a #test</body></html>";
    webView.loadData(html, "text/html", null);
 }
}

Showing "Test is a" (without test) in the recently updated device. If you run this in the emulator you may not see the problem.

Emulator:

enter image description here

Device:

enter image description here

tanutapi
  • 1,083
  • 9
  • 7

1 Answers1

2

I found the solution. From document it said...

the data is base64 or URL encoded

So the html can not be just a simple string. It should be encoded with base64 like this

WebView webView = findViewById(R.id.webView);
String html = "<html><body>This is a #test</body></html>";
String base64 = Base64.encodeToString(html.getBytes(), Base64.NO_PADDING);
webView.loadData(base64, "text/html", "base64");

Then it is working fine. It used to work fine without encoding in the earlier Chrome version.

tanutapi
  • 1,083
  • 9
  • 7