HBiSoft / PickiT

An Android library that returns real paths from Uri's

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SecurityException

ahmadbajwa8282 opened this issue · comments

I'm using ACTION_OPEN_DOCUMENT but still getting this crash.

implementation 'com.github.HBiSoft:PickiT:2.0.5'

  context?.let { context ->
           pdfPicker = PickiT(context, this, activity)
           val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
               addCategory(Intent.CATEGORY_OPENABLE)
               type = "application/pdf"
           }
           launchForPDF.launch(Intent.createChooser(intent, "ChooseFile"))
       }

Fatal Exception: java.lang.RuntimeException: An error occurred while executing doInBackground()
      at android.os.AsyncTask$3.done(AsyncTask.java:353)
      at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
      at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
      at java.util.concurrent.FutureTask.run(FutureTask.java:271)
      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
      at java.lang.Thread.run(Thread.java:764)

Caused by java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.docs.storagebackend.StorageBackendContentProvider from ProcessRecord{20aefd9 3737:com.hmblapps.scanner/u0a260} (pid=3737, uid=10260) requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
      at android.os.Parcel.readException(Parcel.java:2013)
      at android.os.Parcel.readException(Parcel.java:1959)
      at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:4793)
      at android.app.ActivityThread.acquireProvider(ActivityThread.java:5899)
      at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2557)
      at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1780)
      at android.content.ContentResolver.query(ContentResolver.java:738)
      at android.content.ContentResolver.query(ContentResolver.java:704)
      at android.content.ContentResolver.query(ContentResolver.java:662)
      at com.hbisoft.pickit.DownloadAsyncTask.getFileName(DownloadAsyncTask.java:28)
      at com.hbisoft.pickit.DownloadAsyncTask.doInBackground(DownloadAsyncTask.java:209)
      at android.os.AsyncTask$2.call(AsyncTask.java:333)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
      at java.lang.Thread.run(Thread.java:764)

I closed your previous issue because this is not related to the library..

Did you add the following in onActivtyResult?

@Override
public void onActivityResult (int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        Uri mUri = data.getData();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getContext().getContentResolver().takePersistableUriPermission(mUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
            // Now you can pass the Uri to PickiT
        }
    }
}

Ok thanks for your help.