From 4e7aaba77aa9a27ba3e17c5cea4bf59fe729165e Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 12 Aug 2021 19:27:50 +0200 Subject: [PATCH] Android: Add button for opening system file manager Apparently some phones (at least some from Samsung) don't expose the system file manager in the system settings despite it being the only on-device file manager that can open app-specific directories... --- .../activities/UserDataActivity.java | 36 ++++++++++++++++++- .../main/res/layout/activity_user_data.xml | 13 ++++++- .../app/src/main/res/values/strings.xml | 4 ++- 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java index 79fcc09123..532dcc8962 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/UserDataActivity.java @@ -2,19 +2,22 @@ package org.dolphinemu.dolphinemu.activities; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.view.View; +import android.widget.Button; import android.widget.TextView; +import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.utils.DirectoryInitialization; -public class UserDataActivity extends AppCompatActivity +public class UserDataActivity extends AppCompatActivity implements View.OnClickListener { public static void launch(Context context) { @@ -32,6 +35,7 @@ public class UserDataActivity extends AppCompatActivity TextView textType = findViewById(R.id.text_type); TextView textPath = findViewById(R.id.text_path); TextView textAndroid11 = findViewById(R.id.text_android_11); + Button buttonOpenSystemFileManager = findViewById(R.id.button_open_system_file_manager); textType.setText(DirectoryInitialization.isUsingLegacyUserDirectory() ? R.string.user_data_old_location : R.string.user_data_new_location); @@ -41,5 +45,35 @@ public class UserDataActivity extends AppCompatActivity boolean show_android_11_text = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && !DirectoryInitialization.isUsingLegacyUserDirectory(); textAndroid11.setVisibility(show_android_11_text ? View.VISIBLE : View.GONE); + + boolean show_file_manager_button = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R; + buttonOpenSystemFileManager.setVisibility(show_file_manager_button ? View.VISIBLE : View.GONE); + + buttonOpenSystemFileManager.setOnClickListener(this); + } + + @Override + public void onClick(View v) + { + try + { + startActivity(getFileManagerIntent()); + } + 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(); + } + } + + private Intent getFileManagerIntent() + { + // 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.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + return intent; } } diff --git a/Source/Android/app/src/main/res/layout/activity_user_data.xml b/Source/Android/app/src/main/res/layout/activity_user_data.xml index dc7aa50fb9..4c8d3bfe45 100644 --- a/Source/Android/app/src/main/res/layout/activity_user_data.xml +++ b/Source/Android/app/src/main/res/layout/activity_user_data.xml @@ -39,7 +39,18 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/text_path" - app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintBottom_toTopOf="@id/button_open_system_file_manager" app:layout_constraintWidth_max="400dp" /> +