Update FileChooser.java

pull/499/head
okjack 2 years ago
parent 7d581fa4f5
commit 344d100a09
  1. 19
      app/src/main/java/com/fongmi/android/tv/utils/FileChooser.java
  2. 2
      app/src/mobile/java/com/fongmi/android/tv/ui/fragment/SettingFragment.java

@ -53,21 +53,30 @@ public class FileChooser {
show("*/*");
}
public void show(Uri uri) {
show(uri, "*/*");
}
public void show(String mimeType) {
show(mimeType, new String[]{"*/*"}, REQUEST_PICK_FILE);
show(mimeType, new String[]{"*/*"}, null, REQUEST_PICK_FILE);
}
public void show(String[] mimeTypes) {
show("*/*", mimeTypes, REQUEST_PICK_FILE);
show("*/*", mimeTypes, null, REQUEST_PICK_FILE);
}
public void show(Uri uri, String mimeType) {
show(mimeType, new String[]{"*/*"}, uri, REQUEST_PICK_FILE);
}
public void show(String mimeType, String[] mimeTypes, int code) {
public void show(String mimeType, String[] mimeTypes, Uri uri, int code) {
Intent intent = new Intent(Util.isTvBox() ? Intent.ACTION_GET_CONTENT : Intent.ACTION_OPEN_DOCUMENT);
intent.setType(mimeType);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false);
intent.putExtra("android.content.extra.SHOW_ADVANCED", true);
if (uri != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri);
if (intent.resolveActivity(App.get().getPackageManager()) == null) return;
if (fragment != null) fragment.startActivityForResult(Intent.createChooser(intent, ""), code);
}
@ -192,6 +201,10 @@ public class FileChooser {
}
}
public static Uri getUri(String path) {
return Uri.parse("content://com.android.externalstorage.documents/document/primary:" + path);
}
private static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}

@ -353,7 +353,7 @@ public class SettingFragment extends BaseFragment implements ConfigCallback, Sit
}
private void onRestore(View view) {
FileChooser.from(this).type(FileChooser.TYPE_RESTORE).show();
FileChooser.from(this).type(FileChooser.TYPE_RESTORE).show(FileChooser.getUri("TV"));
}
private void onTransmit(View view) {

Loading…
Cancel
Save