DImuthuUpe / AndroidPdfViewer

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
8.18k stars 1.91k forks source link

FileUriExposedException on DefaultLinkHandler.java #983

Open NayabSarfraz opened 3 years ago

NayabSarfraz commented 3 years ago

Hi, I have implemented this library in my project and i am using it laod pdf files. On crashlytics i have got an exception which is specifically on Android 11 right now. The exception detail is as below

DefaultLinkHandler.java line 5 com.github.barteksc.pdfviewer.link.DefaultLinkHandler.handleUri

Fatal Exception: android.os.FileUriExposedException: file://thisisuserpathsoremoved/filetest.pdf exposed beyond app through Intent.getData() at android.os.StrictMode.onFileUriExposed(StrictMode.java:2141) at android.net.Uri.checkFileUriExposed(Uri.java:2391) at android.content.Intent.prepareToLeaveProcess(Intent.java:11837) at android.content.Intent.prepareToLeaveProcess(Intent.java:11786) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1722) at android.app.Activity.startActivityForResult(Activity.java:5374) at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:10) at android.app.Activity.startActivityForResult(Activity.java:5332) at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:10) at android.app.Activity.startActivity(Activity.java:5718) at android.app.Activity.startActivity(Activity.java:5671) at com.github.barteksc.pdfviewer.link.DefaultLinkHandler.handleUri(DefaultLinkHandler.java:5) at com.github.barteksc.pdfviewer.listener.Callbacks.callLinkHandler(Callbacks.java:17) at com.github.barteksc.pdfviewer.DragPinchManager.checkLinkTapped(DragPinchManager.java:17) at com.github.barteksc.pdfviewer.DragPinchManager.onSingleTapConfirmed(DragPinchManager.java:17) at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:354) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:246) at android.app.ActivityThread.main(ActivityThread.java:8419) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

In my app level AndroidMainfest i have added the required permissions

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Also before loading PDF file in my activity i have checked for permissions as well

ActivityCompat.requestPermissions( this@ViewPDFActivity, arrayOf( Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.INTERNET, Manifest.permission.INSTALL_SHORTCUT, Manifest.permission.UNINSTALL_SHORTCUT, Manifest.permission.READ_PHONE_STATE, ), PERMISSIONS_REQ_CODE )

Can somebody please point out what i am missing here? I have tested it on all versions from 6 to 11 i didn't get this issue got this crash on crashlytics.

Any help will be appreciated. Thank you

dityagow commented 3 years ago

I'm also have same problem

mwshubham commented 3 years ago

+1