Change default type verification to create document

This commit is contained in:
J-Jamet
2021-04-04 09:56:09 +02:00
parent d5fbc8393f
commit 818b975111
2 changed files with 5 additions and 3 deletions

View File

@@ -286,7 +286,8 @@ class FileDatabaseSelectActivity : SpecialModeActivity(),
// Show open and create button or special mode // Show open and create button or special mode
when (mSpecialMode) { when (mSpecialMode) {
SpecialMode.DEFAULT -> { SpecialMode.DEFAULT -> {
if (ExternalFileHelper.allowCreateDocumentByStorageAccessFramework(packageManager)) { if (ExternalFileHelper.allowCreateDocumentByStorageAccessFramework(packageManager,
"application/x-keepass")) {
// There is an activity which can handle this intent. // There is an activity which can handle this intent.
createDatabaseButtonView?.visibility = View.VISIBLE createDatabaseButtonView?.visibility = View.VISIBLE
} else{ } else{

View File

@@ -291,13 +291,14 @@ class ExternalFileHelper {
} }
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
fun allowCreateDocumentByStorageAccessFramework(packageManager: PackageManager): Boolean { fun allowCreateDocumentByStorageAccessFramework(packageManager: PackageManager,
typeString: String = "application/octet-stream"): Boolean {
return when { return when {
// To check if a custom file manager can manage the ACTION_CREATE_DOCUMENT // To check if a custom file manager can manage the ACTION_CREATE_DOCUMENT
Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT -> { Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT -> {
packageManager.queryIntentActivities(Intent(Intent.ACTION_CREATE_DOCUMENT).apply { packageManager.queryIntentActivities(Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE) addCategory(Intent.CATEGORY_OPENABLE)
type = "application/x-keepass" type = typeString
}, PackageManager.MATCH_DEFAULT_ONLY).isNotEmpty() }, PackageManager.MATCH_DEFAULT_ONLY).isNotEmpty()
} }
else -> true else -> true