首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >第一个html页面打开,但单击该页面中的任何链接都会导致应用程序崩溃

第一个html页面打开,但单击该页面中的任何链接都会导致应用程序崩溃
EN

Stack Overflow用户
提问于 2018-03-27 17:32:34
回答 1查看 176关注 0票数 1

当应用程序启动时,我的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页面:

代码语言:javascript
复制
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页面:

代码语言:javascript
复制
<?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>
EN

回答 1

Stack Overflow用户

发布于 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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49509235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档