Skip to content

Commit

Permalink
takePersistableUriPermission from gallery image
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhaval2404 committed May 9, 2021
1 parent 9370cf0 commit 42e6e5f
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.core.app.ActivityCompat.requestPermissions
import com.github.dhaval2404.imagepicker.ImagePicker
Expand Down Expand Up @@ -152,9 +153,19 @@ class GalleryProvider(activity: ImagePickerActivity) :
private fun handleResult(data: Intent?) {
val uri = data?.data
if (uri != null) {
takePersistableUriPermission(uri)
activity.setImage(uri)
} else {
setError(R.string.error_failed_pick_gallery_image)
}
}

/**
* Take a persistable URI permission grant that has been offered. Once
* taken, the permission grant will be remembered across device reboots.
*/
private fun takePersistableUriPermission(uri: Uri) {
contentResolver.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
}

}

0 comments on commit 42e6e5f

Please sign in to comment.