当应用程序启动时,我的WebView会打开一个本地html文件。它可以完美地打开,但该页面中的任何链接在单击时都会导致应用程序崩溃。
在bug报告上,它说,
signal 6 (SIGABRT), code-6 (SI_TKILL), fault addr ----- Abort message: 'art/runtime/java_vm_ext:cc:475] JNI DETECTED ERROR IN APPLICATION: JNI NewLocalRef called with pending exception adroid.os.FileUriExposedException: file///android_asset/page2.html exposed beyond app through Intget.getData()
类似的问题以前已经解决过很多次了,但即使在挖掘了不同的解决方案一段时间后,我仍然无法解决这个问题。任何帮助都将不胜感激。
我的MainActivity.java页面:
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
public class MainActivity extends Activity {
private WebView myWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Load WebView with HTML from Assets folder
myWebView = (WebView) findViewById(R.id.webView1);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl("file:///android_asset/page1.html");
}
@Override
public void onBackPressed() {
if (myWebView.canGoBack())
myWebView.goBack();
else
super.onBackPressed();
}
}我的AndroidManifest.xml页面:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.html">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.rimikri.PRx.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>发布于 2018-03-27 17:49:57
正如文档所说:“不鼓励这种暴露,因为接收应用程序可能无法访问共享路径。例如,接收应用程序可能没有请求READ_EXTERNAL_STORAGE运行时权限,或者平台可能跨用户配置文件边界共享Uri。”(https://developer.android.com/reference/android/os/FileUriExposedException.html)
尝试添加READ_EXTERNAL_STORAGE权限:https://developer.android.com/training/permissions/requesting.html
https://stackoverflow.com/questions/49509235
复制相似问题