Catch people disabling system file manager (#7319)

This commit is contained in:
ByteHamster 2024-08-09 19:14:07 +02:00 committed by GitHub
parent f7faf3c8c3
commit 94c5b8aea5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 5 deletions

View File

@ -137,7 +137,8 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat {
try {
chooseOpmlImportPathLauncher.launch("*/*");
} catch (ActivityNotFoundException e) {
Log.e(TAG, "No activity found. Should never happen...");
Snackbar.make(getView(), R.string.unable_to_start_system_file_manager, Snackbar.LENGTH_LONG)
.show();
}
return true;
});
@ -148,7 +149,12 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat {
});
findPreference(PREF_DATABASE_EXPORT).setOnPreferenceClickListener(
preference -> {
backupDatabaseLauncher.launch(dateStampFilename(DATABASE_EXPORT_FILENAME));
try {
backupDatabaseLauncher.launch(dateStampFilename(DATABASE_EXPORT_FILENAME));
} catch (ActivityNotFoundException e) {
Snackbar.make(getView(), R.string.unable_to_start_system_file_manager, Snackbar.LENGTH_LONG)
.show();
}
return true;
});
((SwitchPreferenceCompat) findPreference(PREF_AUTOMATIC_DATABASE_EXPORT))
@ -159,7 +165,6 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat {
try {
automaticBackupLauncher.launch(null);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
Snackbar.make(getView(), R.string.unable_to_start_system_file_manager, Snackbar.LENGTH_LONG)
.show();
}
@ -192,7 +197,12 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat {
builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.setType("*/*");
restoreDatabaseLauncher.launch(intent);
try {
restoreDatabaseLauncher.launch(intent);
} catch (ActivityNotFoundException e) {
Snackbar.make(getView(), R.string.unable_to_start_system_file_manager, Snackbar.LENGTH_LONG)
.show();
}
});
// create and show the alert dialog
@ -271,7 +281,8 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat {
result.launch(intentPickAction);
return;
} catch (ActivityNotFoundException e) {
Log.e(TAG, "No activity found. Should never happen...");
Snackbar.make(getView(), R.string.unable_to_start_system_file_manager, Snackbar.LENGTH_LONG)
.show();
}
// If we are using a SDK lower than API 21 or the implicit intent failed