improve third party image picker intent handling

This commit is contained in:
tibbi 2017-12-22 13:09:34 +01:00
parent a9d48f63ec
commit cdd9dcbae7

View file

@ -443,17 +443,12 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
if (requestCode == PICK_MEDIA && resultData != null) { if (requestCode == PICK_MEDIA && resultData != null) {
val resultIntent = Intent() val resultIntent = Intent()
if (mIsGetImageContentIntent || mIsGetVideoContentIntent || mIsGetAnyContentIntent) { if (mIsThirdPartyIntent) {
when { when {
intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true -> fillExtraOutput(resultData) intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true -> fillExtraOutput(resultData)
resultData.extras?.containsKey(PICKED_PATHS) == true -> fillPickedPaths(resultData, resultIntent) resultData.extras?.containsKey(PICKED_PATHS) == true -> fillPickedPaths(resultData, resultIntent)
else -> fillIntentPath(resultData, resultIntent) else -> fillIntentPath(resultData, resultIntent)
} }
} else if ((mIsPickImageIntent || mIsPickVideoIntent)) {
val path = resultData.data?.path
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
resultIntent.data = uri
resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
} }
setResult(Activity.RESULT_OK, resultIntent) setResult(Activity.RESULT_OK, resultIntent)
@ -491,7 +486,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
clipData.addItem(ClipData.Item(it)) clipData.addItem(ClipData.Item(it))
} }
resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION resultIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
resultIntent.clipData = clipData resultIntent.clipData = clipData
} }
@ -500,7 +495,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID) val uri = getFilePublicUri(File(path), BuildConfig.APPLICATION_ID)
val type = path.getMimeTypeFromPath() val type = path.getMimeTypeFromPath()
resultIntent.setDataAndTypeAndNormalize(uri, type) resultIntent.setDataAndTypeAndNormalize(uri, type)
resultIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION resultIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
} }
private fun itemClicked(path: String) { private fun itemClicked(path: String) {