fix #1030, handle third party intents sent by Instagram style

This commit is contained in:
tibbi 2018-10-28 19:25:41 +01:00
parent 27166b98e2
commit 6eb2f60a55

View file

@ -664,14 +664,22 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
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()
var resultUri: Uri? = null
if (mIsThirdPartyIntent) { if (mIsThirdPartyIntent) {
when { when {
intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true -> fillExtraOutput(resultData) intent.extras?.containsKey(MediaStore.EXTRA_OUTPUT) == true -> {
resultUri = 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)
} }
} }
if (resultUri != null) {
resultIntent.data = resultUri
resultIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
setResult(Activity.RESULT_OK, resultIntent) setResult(Activity.RESULT_OK, resultIntent)
finish() finish()
} else if (requestCode == PICK_WALLPAPER) { } else if (requestCode == PICK_WALLPAPER) {
@ -682,22 +690,25 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
super.onActivityResult(requestCode, resultCode, resultData) super.onActivityResult(requestCode, resultCode, resultData)
} }
private fun fillExtraOutput(resultData: Intent) { private fun fillExtraOutput(resultData: Intent): Uri? {
val path = resultData.data.path val file = File(resultData.data.path)
var inputStream: InputStream? = null var inputStream: InputStream? = null
var outputStream: OutputStream? = null var outputStream: OutputStream? = null
try { try {
val output = intent.extras.get(MediaStore.EXTRA_OUTPUT) as Uri val output = intent.extras.get(MediaStore.EXTRA_OUTPUT) as Uri
inputStream = FileInputStream(File(path)) inputStream = FileInputStream(file)
outputStream = contentResolver.openOutputStream(output) outputStream = contentResolver.openOutputStream(output)
inputStream.copyTo(outputStream) inputStream.copyTo(outputStream)
} catch (e: SecurityException) { } catch (e: SecurityException) {
showErrorToast(e) showErrorToast(e)
} catch (ignored: FileNotFoundException) { } catch (ignored: FileNotFoundException) {
return getFilePublicUri(file, BuildConfig.APPLICATION_ID)
} finally { } finally {
inputStream?.close() inputStream?.close()
outputStream?.close() outputStream?.close()
} }
return null
} }
private fun fillPickedPaths(resultData: Intent, resultIntent: Intent) { private fun fillPickedPaths(resultData: Intent, resultIntent: Intent) {