Merge pull request #10276 from JosJuice/android-fix-file-manager

Android: Fix opening system file manager
This commit is contained in:
Mai M 2021-12-15 00:03:16 -05:00 committed by GitHub
commit 66fc335c11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 7 deletions

View File

@ -59,22 +59,33 @@ public class UserDataActivity extends AppCompatActivity implements View.OnClickL
{ {
try try
{ {
startActivity(getFileManagerIntent()); // First, try the package name used on "normal" phones
startActivity(getFileManagerIntent("com.google.android.documentsui"));
} }
catch (ActivityNotFoundException e) catch (ActivityNotFoundException e)
{ {
new AlertDialog.Builder(this, R.style.DolphinDialogBase) try
.setMessage(R.string.user_data_open_system_file_manager_failed) {
.setPositiveButton(R.string.ok, null) // Next, try the AOSP package name
.show(); startActivity(getFileManagerIntent("com.android.documentsui"));
}
catch (ActivityNotFoundException e2)
{
// Activity not found. Perhaps it was removed by the OEM, or by some new Android version
// that didn't exist at the time of writing. Not much we can do other than tell the user
new AlertDialog.Builder(this, R.style.DolphinDialogBase)
.setMessage(R.string.user_data_open_system_file_manager_failed)
.setPositiveButton(R.string.ok, null)
.show();
}
} }
} }
private Intent getFileManagerIntent() private Intent getFileManagerIntent(String packageName)
{ {
// Fragile, but some phones don't expose the system file manager in any better way // Fragile, but some phones don't expose the system file manager in any better way
Intent intent = new Intent(Intent.ACTION_MAIN); Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.documentsui", "com.android.documentsui.files.FilesActivity"); intent.setClassName(packageName, "com.android.documentsui.files.FilesActivity");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return intent; return intent;
} }