mirror of
https://github.com/Myzel394/Alibi.git
synced 2025-06-18 23:05:26 +02:00
fix: Improve Doctor's checkIfFileSaverDialogIsAvailable
This commit is contained in:
parent
cba150b72e
commit
9bc6908bb9
@ -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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user