背景
をandroid_assetフォルダにアクセスする際のAndroid 7.0へ移行した後、私は私のWebViewに次のURLをロードするときに私のアプリは、FileUriExposedException
でクラッシュしていました気づいFileUriExposedExceptionの取り扱い:のAndroid 7.0への移行 -
webView.loadUrl("file:///android_asset/myFolder/myFile.html")
私が読んでhereこれは、アンドロイド7.0で導入されたファイルシステムのアクセス許可が変更されたために発生します。ここで、FileUriExposedException
は、インテント内でfile:// Uriを共有しようとしたときにスローされます。
私は一時的なアクセス権限(here)のためFileProvider
を使用していた、その周り提案作業を実施しようとしたが、私は唯一の使用可能なパスことを見るように私はandroid_asset
フォルダに対して、この作品を作るための方法を知りませんFileProvider
には、内部と外部のストレージパスが関係します。 HelpActivityから>
Intent intent = new Intent(view.getContext(), HelpActivity.class);
startActivity(intent);
- - MainActivityから
コード
>
webView.loadUrl("file:///android_asset/help/index.html");
質問
誰に必要とするとき、この例外を回避するための良い方法を知っていますWebViewのassetsフォルダからファイルを読み込みますか?
android.os.FileUriExposedException: file:///android_asset/help/help.html exposed beyond app through Intent.getData()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1958)
at android.net.Uri.checkFileUriExposed(Uri.java:2348)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9766)
at android.content.Intent.prepareToLeaveProcess(Intent.java:9720)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1609)
at android.app.Activity.startActivityForResult(Activity.java:4472)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivityForResult(Activity.java:4430)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:859)
at android.app.Activity.startActivity(Activity.java:4791)
at android.app.Activity.startActivity(Activity.java:4759)
at android.content.ContextWrapper.startActivity(ContextWrapper.java:366)
at org.chromium.android_webview.ResourcesContextWrapperFactory$WebViewContextWrapper.startActivity(ResourcesContextWrapperFactory.java:118)
at org.chromium.android_webview.AwContentsClient.sendBrowsingIntent(AwContentsClient.java:203)
at org.chromium.android_webview.AwContentsClient.shouldIgnoreNavigation(AwContentsClient.java:170)
at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(AwContentsClientBridge.java:352)
at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:41)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
"Android 7.0に移行した後、私のwebViewに次のURLを読み込むときに、私のアプリがFileUriExposedExceptionでクラッシュしていたことがわかりました。あなたは完全なJavaスタックトレースを投稿できますか? – CommonsWare
@CommonsWareおっと、申し訳ありません、私はそれを追加しました。 – Lauren
stacktraceはstartActivity()によって使用される意図でそのファイルuriを渡そうとするように見えます。 – greenapps