我正在尝试制作一个应用程序,打开一个本地 html 页面,该页面具有链接到其他 2 个页面的超链接。所有这些 html 文件都放在 assets 文件夹中。现在,当我触摸第一个 html 文件的超链接时,应用程序在打开另一个 html 文件时崩溃。
package com.example.rishabh.webviewdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends AppCompatActivity {
WebView web;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
web= (WebView) findViewById(R.id.webview);
web.loadUrl("file:///android_asset/1.html");
}
}
Run Code Online (Sandbox Code Playgroud)
这是日志
W/System.err: android.os.FileUriExposedException:file:///android_asset/2.html exposed beyond app through Intent.getData()
W/System.err: at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
W/System.err: at android.net.Uri.checkFileUriExposed(Uri.java:2346)
W/System.err: at android.content.Intent.prepareToLeaveProcess(Intent.java:8965)
W/System.err: at android.content.Intent.prepareToLeaveProcess(Intent.java:8926)
W/System.err: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1517)
W/System.err: at android.app.Activity.startActivityForResult(Activity.java:4225)
W/System.err: at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
W/System.err: at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:77)
W/System.err: at android.app.Activity.startActivityForResult(Activity.java:4183)
W/System.err: at …Run Code Online (Sandbox Code Playgroud)