The javascript code in my html file can run correctly when I use WebView.load URL to load that html file. But i want to use WebView.loadData ,then i read that html file in a String ,and use WebView.loadData. The JavaScript code in html can't run successfully. who can help me? thanks.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
try {
InputStream is=this.getAssets().open("COPY-ME.html");
ByteArrayOutputStream baos=new ByteArrayOutputStream();
int i=1;
while ((i=is.read())!=-1) {
baos.write(i);
}
data=baos.toString();
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
webView.loadData(data, "text/html", "utf-8");