Skip to content

Commit

Permalink
Exclude kDrive in openWith with the PDF reader to avoid a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Mar 14, 2024
1 parent c3d1d1f commit 26f7463
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions app/src/main/java/com/infomaniak/drive/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,26 @@ object Utils {
}
}

fun Context.getExtensionType(uri: Uri) = contentResolver.getType(uri)

fun Context.openWithIntent(uri: Uri): Intent {
return Intent().apply {
val openWithIntent = Intent().apply {
action = Intent.ACTION_VIEW
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
setDataAndType(uri, getExtensionType(uri))
setDataAndType(uri, contentResolver.getType(uri))
}

val openWithIntentLists = mutableListOf<Intent>()
packageManager.queryIntentActivities(openWithIntent, 0).takeIf { it.isNotEmpty() }?.forEach { resInfo ->
val resInfoPackageName = resInfo.activityInfo.packageName
if (!resInfoPackageName.lowercase().contains(packageName)) {
with(Intent(openWithIntent)) {
setPackage(resInfoPackageName)
openWithIntentLists.add(this)
}
}
}

return Intent.createChooser(openWithIntentLists.removeAt(0), null).apply {
putExtra(Intent.EXTRA_INITIAL_INTENTS, openWithIntentLists.toTypedArray())
}
}

Expand Down

0 comments on commit 26f7463

Please sign in to comment.