如何 link html 页 Android 8
How to link html pages in Android 8
我有一个小的联机帮助,由几个 HTML link 相互编辑而成。
这在过去工作得很好,但是 Android 8 只能显示入口页面,只要我点击任何 link,我就会得到:
10-08 09:04:17.616 22871 22871 E AndroidRuntime: FATAL EXCEPTION: main
10-08 09:04:17.616 22871 22871 E AndroidRuntime: Process: net.sourceforge.uiq3.fx602p, PID: 22871
10-08 09:04:17.616 22871 22871 E AndroidRuntime: android.os.FileUriExposedException: file:///android_asset/Modes.html exposed beyond app through Intent.getData()
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.net.Uri.checkFileUriExposed(Uri.java:2356)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.content.Intent.prepareToLeaveProcess(Intent.java:10511)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.content.Intent.prepareToLeaveProcess(Intent.java:10465)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.app.Activity.startActivityForResult(Activity.java:4564)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.app.Activity.startActivityForResult(Activity.java:4522)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.app.Activity.startActivity(Activity.java:4883)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.app.Activity.startActivity(Activity.java:4851)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.content.ContextWrapper.startActivity(ContextWrapper.java:377)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at aiM.startActivity(SourceFile:22)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at agA.a(SourceFile:34)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(SourceFile:173)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.os.MessageQueue.nativePollOnce(Native Method)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.os.MessageQueue.next(MessageQueue.java:325)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.os.Looper.loop(Looper.java:142)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6944)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
当然,所有页面都显示在应用程序内部,"leaked" 没有显示在应用程序外部。即使:这只是在线帮助,如果是在线帮助也不会在意。
够了咆哮:如何解决这个问题?
更新 1:
页面只有一个简单的布局和几乎是空的 activity:
<LinearLayout
android:layout_height='match_parent'
android:layout_width='match_parent'
xmlns:android='http://schemas.android.com/apk/res/android'
>
<WebView
android:id='@+id/Help'
android:layout_height='match_parent'
android:layout_width='match_parent'
></WebView>
</LinearLayout>
@igor_rb 建议重载 shouldOverrideUrlLoading
和 WebViewClient
— 但我现在实际上并没有使用 WebViewClient
。
您可以尝试覆盖 shouldOverrideUrlLoading
方法,more info。
Give the host application a chance to take control when a URL is about to be loaded in the current WebView. If a WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the URL. If a WebViewClient is provided, returning true causes the current WebView to abort loading the URL, while returning false causes the WebView to continue loading the URL as usual.
例如,您可以简单地从他那里尝试 return false:
WebViewClient client = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
};
我有一个小的联机帮助,由几个 HTML link 相互编辑而成。
这在过去工作得很好,但是 Android 8 只能显示入口页面,只要我点击任何 link,我就会得到:
10-08 09:04:17.616 22871 22871 E AndroidRuntime: FATAL EXCEPTION: main
10-08 09:04:17.616 22871 22871 E AndroidRuntime: Process: net.sourceforge.uiq3.fx602p, PID: 22871
10-08 09:04:17.616 22871 22871 E AndroidRuntime: android.os.FileUriExposedException: file:///android_asset/Modes.html exposed beyond app through Intent.getData()
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.net.Uri.checkFileUriExposed(Uri.java:2356)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.content.Intent.prepareToLeaveProcess(Intent.java:10511)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.content.Intent.prepareToLeaveProcess(Intent.java:10465)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.app.Activity.startActivityForResult(Activity.java:4564)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.app.Activity.startActivityForResult(Activity.java:4522)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.app.Activity.startActivity(Activity.java:4883)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.app.Activity.startActivity(Activity.java:4851)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.content.ContextWrapper.startActivity(ContextWrapper.java:377)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at aiM.startActivity(SourceFile:22)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at agA.a(SourceFile:34)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(SourceFile:173)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.os.MessageQueue.nativePollOnce(Native Method)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.os.MessageQueue.next(MessageQueue.java:325)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.os.Looper.loop(Looper.java:142)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6944)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
10-08 09:04:17.616 22871 22871 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
当然,所有页面都显示在应用程序内部,"leaked" 没有显示在应用程序外部。即使:这只是在线帮助,如果是在线帮助也不会在意。
够了咆哮:如何解决这个问题?
更新 1:
页面只有一个简单的布局和几乎是空的 activity:
<LinearLayout
android:layout_height='match_parent'
android:layout_width='match_parent'
xmlns:android='http://schemas.android.com/apk/res/android'
>
<WebView
android:id='@+id/Help'
android:layout_height='match_parent'
android:layout_width='match_parent'
></WebView>
</LinearLayout>
@igor_rb 建议重载 shouldOverrideUrlLoading
和 WebViewClient
— 但我现在实际上并没有使用 WebViewClient
。
您可以尝试覆盖 shouldOverrideUrlLoading
方法,more info。
Give the host application a chance to take control when a URL is about to be loaded in the current WebView. If a WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the URL. If a WebViewClient is provided, returning true causes the current WebView to abort loading the URL, while returning false causes the WebView to continue loading the URL as usual.
例如,您可以简单地从他那里尝试 return false:
WebViewClient client = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
};