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...
This commit is contained in:
JosJuice 2021-08-12 19:27:50 +02:00
parent 9c8bb24293
commit 4e7aaba77a
3 changed files with 50 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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" />
<Button
android:id="@+id/button_open_system_file_manager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/spacing_medlarge"
android:text="@string/user_data_open_system_file_manager"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/text_android_11"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -328,7 +328,9 @@
<string name="user_data_submenu">User Data</string>
<string name="user_data_old_location">Your user data is stored in a location which will <b>not</b> be deleted when you uninstall the app:</string>
<string name="user_data_new_location">Your user data is stored in a location which <b>will be deleted</b> when you uninstall the app:</string>
<string name="user_data_new_location_android_11">Because you\'re using Android 11 or newer, you can\'t access this location using file manager apps. However, you can access it using the file manager in the system settings, or by connecting your device to a PC.</string>
<string name="user_data_new_location_android_11">Because you\'re using Android 11 or newer, you can\'t access this location using file manager apps. However, you can access it using the system file manager, or by connecting your device to a PC.</string>
<string name="user_data_open_system_file_manager">Open System File Manager</string>
<string name="user_data_open_system_file_manager_failed">Sorry, Dolphin couldn\'t find the system file manager on your device.</string>
<!-- Miscellaneous -->
<string name="yes">Yes</string>