diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java index e043b36f24..6486b0353b 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsActivity.java @@ -3,6 +3,7 @@ package org.dolphinemu.dolphinemu.features.settings.ui; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; import android.provider.Settings; import android.view.Menu; @@ -18,6 +19,7 @@ import androidx.lifecycle.ViewModelProvider; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.ui.main.MainActivity; +import org.dolphinemu.dolphinemu.ui.main.MainPresenter; import org.dolphinemu.dolphinemu.ui.main.TvMainActivity; import org.dolphinemu.dolphinemu.utils.FileBrowserHelper; import org.dolphinemu.dolphinemu.utils.TvUtil; @@ -170,11 +172,31 @@ public final class SettingsActivity extends AppCompatActivity implements Setting // If the user picked a file, as opposed to just backing out. if (resultCode == MainActivity.RESULT_OK) { - String path = FileBrowserHelper.getSelectedPath(result); - getFragment().getAdapter().onFilePickerConfirmation(path); + if (requestCode == MainPresenter.REQUEST_SD_FILE) + { + Uri uri = canonicalizeIfPossible(result.getData()); + + int takeFlags = result.getFlags() & + (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + getContentResolver().takePersistableUriPermission(uri, takeFlags); + + getFragment().getAdapter().onFilePickerConfirmation(uri.toString()); + } + else + { + String path = FileBrowserHelper.getSelectedPath(result); + getFragment().getAdapter().onFilePickerConfirmation(path); + } } } + @NonNull + private Uri canonicalizeIfPossible(@NonNull Uri uri) + { + Uri canonicalizedUri = getContentResolver().canonicalize(uri); + return canonicalizedUri != null ? canonicalizedUri : uri; + } + @Override public void showLoading() { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java index 8873a668fb..f8e6d312b7 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/ui/SettingsAdapter.java @@ -2,6 +2,9 @@ package org.dolphinemu.dolphinemu.features.settings.ui; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; +import android.os.Build; +import android.provider.DocumentsContract; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -288,21 +291,28 @@ public final class SettingsAdapter extends RecyclerView.Adapter extensions; switch (filePicker.getRequestType()) { case MainPresenter.REQUEST_SD_FILE: - extensions = FileBrowserHelper.RAW_EXTENSION; + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); + intent.addCategory(Intent.CATEGORY_OPENABLE); + intent.setType("*/*"); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) + { + intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, + filePicker.getSelectedValue(mView.getSettings())); + } + + mView.getActivity().startActivityForResult(intent, filePicker.getRequestType()); break; case MainPresenter.REQUEST_GAME_FILE: - extensions = FileBrowserHelper.GAME_EXTENSIONS; + FileBrowserHelper.openFilePicker(mView.getActivity(), filePicker.getRequestType(), false, + FileBrowserHelper.GAME_EXTENSIONS); break; default: throw new InvalidParameterException("Unhandled request code"); } - - FileBrowserHelper.openFilePicker(mView.getActivity(), filePicker.getRequestType(), false, - extensions); } public void onFilePickerConfirmation(String selectedFile)