Skip to content

Instantly share code, notes, and snippets.

@DanishAmjad12
Created September 1, 2022 15:00
Show Gist options
  • Save DanishAmjad12/14a1ed3f82ac85060fa9123c7001efb8 to your computer and use it in GitHub Desktop.
Save DanishAmjad12/14a1ed3f82ac85060fa9123c7001efb8 to your computer and use it in GitHub Desktop.
private fun galleryIntent() {
val galleryIntent:Intent
if (Build.VERSION.SDK_INT >= Versions.ANDROID_10)
galleryIntent = Intent(Intent.ACTION_PICK,MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
else
galleryIntent = Intent()
galleryFile = FileUtils.createTempFileInStorage(this, FileUtil.getProfileName())
galleryIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
galleryIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
galleryIntent.type = "image/*"
galleryIntent.action = Intent.ACTION_GET_CONTENT
galleryIntent.addCategory(Intent.CATEGORY_OPENABLE)
galleryIntent.putExtra(MediaStore.EXTRA_OUTPUT, FileUtil.getUri(this, galleryFile))
galleryIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)
if (galleryIntent.resolveActivity(packageManager) != null) {
startActivityForResult(galleryIntent, ReqCode.ACTIVITY_ANDROID_GALLERY)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment