Skip to content

Commit

Permalink
Merge pull request #10276 from JosJuice/android-fix-file-manager
Browse files Browse the repository at this point in the history
Android: Fix opening system file manager
  • Loading branch information
lioncash committed Dec 15, 2021
2 parents 185475f + 974c7f4 commit 66fc335
Showing 1 changed file with 18 additions and 7 deletions.
Expand Up @@ -59,22 +59,33 @@ public void onClick(View v)
{
try
{
startActivity(getFileManagerIntent());
// First, try the package name used on "normal" phones
startActivity(getFileManagerIntent("com.google.android.documentsui"));
}
catch (ActivityNotFoundException e)
{
new AlertDialog.Builder(this, R.style.DolphinDialogBase)
.setMessage(R.string.user_data_open_system_file_manager_failed)
.setPositiveButton(R.string.ok, null)
.show();
try
{
// Next, try the AOSP package name
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
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);
return intent;
}
Expand Down

0 comments on commit 66fc335

Please sign in to comment.