I / chromium:[INFO:CONSOLE(0)]“不允许加载本地资源: file:///android_asset/webkit/android-weberror.png“,来源: data:text / html,chromewebdata(0)我找到了很多方法来解决 就如: webView.loadUrl( “文件:///android_asset/assets/wwww/js/mypage.html”);
webView.loadUrl("file:///assets/mypage.html");
webView.loadUrl("file:///android_asset/mypage.html");
所有这些都无法运作。
答案 0 :(得分:0)
请确保您的文件mypage.html确实存在于/assets
目录中:
webView.loadUrl("file:///android_asset/mypage.html");
您需要在AndroidManifest.xml中声明权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
使用Android 6.0+必须手动请求WRITE_EXTERNAL_STORAGE
权限:
private void checkExternalStoragePermission() {
int permissionCheck = ContextCompat.checkSelfPermission(
this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
Log.i("Message", "PERMISSION NOT SET.");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, 225);
} else {
Log.i("Message", "Permission OK!");
}
}