diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameFileCache.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameFileCache.java index 2fdc0cb179..a15e734d0b 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameFileCache.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/model/GameFileCache.java @@ -6,6 +6,7 @@ import org.dolphinemu.dolphinemu.NativeLibrary; import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting; import org.dolphinemu.dolphinemu.features.settings.model.Settings; import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile; +import org.dolphinemu.dolphinemu.utils.ContentHandler; import org.dolphinemu.dolphinemu.utils.IniFile; import java.io.File; @@ -58,8 +59,7 @@ public class GameFileCache String path = dolphinIni.getString(Settings.SECTION_INI_GENERAL, SettingsFile.KEY_ISO_PATH_BASE + i, ""); - File folder = new File(path); - if (folder.exists()) + if (path.startsWith("content://") ? ContentHandler.exists(path) : new File(path).exists()) { pathSet.add(path); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java index c7515cc511..f09668713f 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java @@ -163,7 +163,8 @@ public final class MainActivity extends AppCompatActivity implements MainView @Override public void launchFileListActivity() { - FileBrowserHelper.openDirectoryPicker(this, FileBrowserHelper.GAME_EXTENSIONS); + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); + startActivityForResult(intent, MainPresenter.REQUEST_DIRECTORY); } @Override @@ -201,7 +202,7 @@ public final class MainActivity extends AppCompatActivity implements MainView switch (requestCode) { case MainPresenter.REQUEST_DIRECTORY: - mPresenter.onDirectorySelected(FileBrowserHelper.getSelectedPath(result)); + mPresenter.onDirectorySelected(result); break; case MainPresenter.REQUEST_GAME_FILE: diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java index a161ac782b..92a4096bfb 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainPresenter.java @@ -2,9 +2,11 @@ package org.dolphinemu.dolphinemu.ui.main; import android.app.Activity; import android.content.BroadcastReceiver; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.net.Uri; import android.widget.Toast; import androidx.appcompat.app.AlertDialog; @@ -17,6 +19,9 @@ import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag; import org.dolphinemu.dolphinemu.model.GameFileCache; import org.dolphinemu.dolphinemu.services.GameFileCacheService; import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner; +import org.dolphinemu.dolphinemu.utils.FileBrowserHelper; + +import java.util.Set; public final class MainPresenter { @@ -116,9 +121,19 @@ public final class MainPresenter } } - public void onDirectorySelected(String dir) + public void onDirectorySelected(Intent result) { - mDirToAdd = dir; + ContentResolver contentResolver = mContext.getContentResolver(); + Uri uri = result.getData(); + + Uri canonicalizedUri = contentResolver.canonicalize(uri); + if (canonicalizedUri != null) + uri = canonicalizedUri; + + int takeFlags = result.getFlags() & Intent.FLAG_GRANT_READ_URI_PERMISSION; + mContext.getContentResolver().takePersistableUriPermission(uri, takeFlags); + + mDirToAdd = uri.toString(); } public void installWAD(String file) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java index 8d3d6f2aec..262cff6c00 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java @@ -168,7 +168,8 @@ public final class TvMainActivity extends FragmentActivity implements MainView @Override public void launchFileListActivity() { - FileBrowserHelper.openDirectoryPicker(this, FileBrowserHelper.GAME_EXTENSIONS); + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); + startActivityForResult(intent, MainPresenter.REQUEST_DIRECTORY); } @Override @@ -225,7 +226,7 @@ public final class TvMainActivity extends FragmentActivity implements MainView switch (requestCode) { case MainPresenter.REQUEST_DIRECTORY: - mPresenter.onDirectorySelected(FileBrowserHelper.getSelectedPath(result)); + mPresenter.onDirectorySelected(result); break; case MainPresenter.REQUEST_GAME_FILE: