Android: Use old folder picker on Android TV
See the comment I added to the code. This is a rather serious issue for Android TV users from what I've heard.
This commit is contained in:
parent
452aad29f1
commit
116a5a79da
|
@ -162,10 +162,17 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launchFileListActivity()
|
public void launchFileListActivity()
|
||||||
|
{
|
||||||
|
if (DirectoryInitialization.preferOldFolderPicker(this))
|
||||||
|
{
|
||||||
|
FileBrowserHelper.openDirectoryPicker(this, FileBrowserHelper.GAME_EXTENSIONS);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||||
startActivityForResult(intent, MainPresenter.REQUEST_DIRECTORY);
|
startActivityForResult(intent, MainPresenter.REQUEST_DIRECTORY);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launchOpenFileActivity()
|
public void launchOpenFileActivity()
|
||||||
|
@ -202,7 +209,14 @@ public final class MainActivity extends AppCompatActivity implements MainView
|
||||||
switch (requestCode)
|
switch (requestCode)
|
||||||
{
|
{
|
||||||
case MainPresenter.REQUEST_DIRECTORY:
|
case MainPresenter.REQUEST_DIRECTORY:
|
||||||
|
if (DirectoryInitialization.preferOldFolderPicker(this))
|
||||||
|
{
|
||||||
|
mPresenter.onDirectorySelected(FileBrowserHelper.getSelectedPath(result));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
mPresenter.onDirectorySelected(result);
|
mPresenter.onDirectorySelected(result);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MainPresenter.REQUEST_GAME_FILE:
|
case MainPresenter.REQUEST_GAME_FILE:
|
||||||
|
|
|
@ -112,6 +112,17 @@ public final class MainPresenter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a selection is made using the legacy folder picker.
|
||||||
|
*/
|
||||||
|
public void onDirectorySelected(String dir)
|
||||||
|
{
|
||||||
|
mDirToAdd = dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a selection is made using the Storage Access Framework folder picker.
|
||||||
|
*/
|
||||||
public void onDirectorySelected(Intent result)
|
public void onDirectorySelected(Intent result)
|
||||||
{
|
{
|
||||||
Uri uri = result.getData();
|
Uri uri = result.getData();
|
||||||
|
|
|
@ -167,10 +167,17 @@ public final class TvMainActivity extends FragmentActivity implements MainView
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launchFileListActivity()
|
public void launchFileListActivity()
|
||||||
|
{
|
||||||
|
if (DirectoryInitialization.preferOldFolderPicker(this))
|
||||||
|
{
|
||||||
|
FileBrowserHelper.openDirectoryPicker(this, FileBrowserHelper.GAME_EXTENSIONS);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||||
startActivityForResult(intent, MainPresenter.REQUEST_DIRECTORY);
|
startActivityForResult(intent, MainPresenter.REQUEST_DIRECTORY);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void launchOpenFileActivity()
|
public void launchOpenFileActivity()
|
||||||
|
@ -226,7 +233,14 @@ public final class TvMainActivity extends FragmentActivity implements MainView
|
||||||
switch (requestCode)
|
switch (requestCode)
|
||||||
{
|
{
|
||||||
case MainPresenter.REQUEST_DIRECTORY:
|
case MainPresenter.REQUEST_DIRECTORY:
|
||||||
|
if (DirectoryInitialization.preferOldFolderPicker(this))
|
||||||
|
{
|
||||||
|
mPresenter.onDirectorySelected(FileBrowserHelper.getSelectedPath(result));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
mPresenter.onDirectorySelected(result);
|
mPresenter.onDirectorySelected(result);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MainPresenter.REQUEST_GAME_FILE:
|
case MainPresenter.REQUEST_GAME_FILE:
|
||||||
|
|
|
@ -9,6 +9,7 @@ package org.dolphinemu.dolphinemu.utils;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
|
@ -347,6 +348,30 @@ public final class DirectoryInitialization
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isExternalStorageLegacy()
|
||||||
|
{
|
||||||
|
return Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || Environment.isExternalStorageLegacy();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean preferOldFolderPicker(Context context)
|
||||||
|
{
|
||||||
|
// As of January 2021, ACTION_OPEN_DOCUMENT_TREE seems to be broken on the Nvidia Shield TV
|
||||||
|
// (the activity can't be navigated correctly with a gamepad). We can use the old folder picker
|
||||||
|
// for the time being - Android 11 hasn't been released for this device. We have an explicit
|
||||||
|
// check for Android 11 below in hopes that Nvidia will fix this before releasing Android 11.
|
||||||
|
//
|
||||||
|
// No Android TV device other than the Nvidia Shield TV is known to have an implementation
|
||||||
|
// of ACTION_OPEN_DOCUMENT or ACTION_OPEN_DOCUMENT_TREE that even launches, but "fortunately"
|
||||||
|
// for us, the Nvidia Shield TV is the only Android TV device in existence so far that can
|
||||||
|
// run Dolphin at all (due to the 64-bit requirement), so we can ignore this problem.
|
||||||
|
//
|
||||||
|
// All phones which are running a compatible version of Android support ACTION_OPEN_DOCUMENT and
|
||||||
|
// ACTION_OPEN_DOCUMENT_TREE, as this is required by the Android CTS (unlike with Android TV).
|
||||||
|
|
||||||
|
return Build.VERSION.SDK_INT < Build.VERSION_CODES.R && isExternalStorageLegacy() &&
|
||||||
|
TvUtil.isLeanback(context);
|
||||||
|
}
|
||||||
|
|
||||||
private static native void CreateUserDirectories();
|
private static native void CreateUserDirectories();
|
||||||
|
|
||||||
private static native void SetSysDirectory(String path);
|
private static native void SetSysDirectory(String path);
|
||||||
|
|
Loading…
Reference in New Issue