Add tvbox check

pull/178/head
FongMi 2 years ago
parent b7a46bbcd2
commit bd1ff02fbe
  1. 2
      app/build.gradle
  2. 13
      app/src/main/java/com/fongmi/android/tv/utils/FileChooser.java
  3. 35
      app/src/main/java/com/fongmi/android/tv/utils/Util.java

@ -11,7 +11,7 @@ android {
minSdk 21
targetSdk 28
versionCode 210
versionName "20231210"
versionName "20231210#2"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]

@ -47,7 +47,7 @@ public class FileChooser {
}
public void show(String mimeType, String[] mimeTypes, int code) {
Intent intent = new Intent(getAction());
Intent intent = new Intent(Util.isTvBox() ? Intent.ACTION_OPEN_DOCUMENT : Intent.ACTION_GET_CONTENT);
intent.setType(mimeType);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
@ -57,17 +57,6 @@ public class FileChooser {
if (fragment != null) fragment.startActivityForResult(Intent.createChooser(intent, ""), code);
}
private String getAction() {
return hasSAFChooser() ? Intent.ACTION_OPEN_DOCUMENT : Intent.ACTION_GET_CONTENT;
}
private boolean hasSAFChooser() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("video/*");
return intent.resolveActivity(App.get().getPackageManager()) != null;
}
public static boolean isValid(Context context, Uri uri) {
try {
return DocumentsContract.isDocumentUri(context, uri) || ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()) || ContentResolver.SCHEME_FILE.equalsIgnoreCase(uri.getScheme());

@ -1,12 +1,15 @@
package com.fongmi.android.tv.utils;
import android.app.Activity;
import android.app.UiModeManager;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.os.Build;
import android.os.IBinder;
import android.os.Parcelable;
@ -137,4 +140,36 @@ public class Util {
return Intent.createChooser(intent, null);
}
}
public static boolean hasSAFChooser() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("video/*");
return intent.resolveActivity(App.get().getPackageManager()) != null;
}
public static boolean isTvBox() {
PackageManager pm = App.get().getPackageManager();
if (Configuration.UI_MODE_TYPE_TELEVISION == ((UiModeManager) App.get().getSystemService(Context.UI_MODE_SERVICE)).getCurrentModeType()) {
return true;
}
if (pm.hasSystemFeature("amazon.hardware.fire_tv")) {
return true;
}
if (!hasSAFChooser()) {
return true;
}
if (Build.VERSION.SDK_INT < 30) {
if (!pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) {
return true;
}
if (pm.hasSystemFeature("android.hardware.hdmi.cec")) {
return true;
}
if (Build.MANUFACTURER.equalsIgnoreCase("zidoo")) {
return true;
}
}
return false;
}
}

Loading…
Cancel
Save