fix: Improve Doctor's checkIfFileSaverDialogIsAvailable

This commit is contained in:
Myzel394 2024-01-01 15:23:49 +01:00
parent cba150b72e
commit 9bc6908bb9
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B

View File

@ -2,13 +2,33 @@ package app.myzel394.alibi.helpers
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
data class Doctor(
val context: Context
) {
fun checkIfFileSaverDialogIsAvailable(): Boolean {
val fileSaver = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
// Since API 30, we can't query other packages so easily anymore
// (see https://developer.android.com/training/package-visibility).
// For now, we assume the user has a file saver app installed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return true
}
return fileSaver.resolveActivity(context.packageManager) != null
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
if (intent.resolveActivity(context.packageManager) != null) {
return true
}
val results =
context.packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (results.isNotEmpty()) {
return true;
}
return false
}
}