Java Code Examples for android.content.res.Configuration#UI_MODE_TYPE_TELEVISION

The following examples show how to use android.content.res.Configuration#UI_MODE_TYPE_TELEVISION . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeviceTypeResolver.java    From react-native-device-info with MIT License 6 votes vote down vote up
public DeviceType getDeviceType() {
  // Detect TVs via ui mode (Android TVs) or system features (Fire TV).
  if (context.getPackageManager().hasSystemFeature("amazon.hardware.fire_tv")) {
    return DeviceType.TV;
  }

  UiModeManager uiManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
  if (uiManager != null && uiManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
    return DeviceType.TV;
  }

  DeviceType deviceTypeFromConfig = getDeviceTypeFromResourceConfiguration();

  if (deviceTypeFromConfig != null && deviceTypeFromConfig != DeviceType.UNKNOWN) {
    return deviceTypeFromConfig;
  }

  return getDeviceTypeFromPhysicalSize();
}
 
Example 2
Source File: Utils.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true when running Android TV
 *
 * @param c Context to detect UI Mode.
 * @return true when device is running in tv mode, false otherwise.
 */
public static String getDeviceType(Context c) {
    UiModeManager uiModeManager = (UiModeManager) c.getSystemService(Context.UI_MODE_SERVICE);
    int modeType = uiModeManager.getCurrentModeType();
    switch (modeType){
        case Configuration.UI_MODE_TYPE_TELEVISION:
            return "TELEVISION";
        case Configuration.UI_MODE_TYPE_WATCH:
            return "WATCH";
        case Configuration.UI_MODE_TYPE_NORMAL:
            String type = isTablet(c) ? "TABLET" : "PHONE";
            return type;
        case Configuration.UI_MODE_TYPE_UNDEFINED:
            return "UNKOWN";
        default:
            return "";
    }
}
 
Example 3
Source File: Utils.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true when running Android TV
 *
 * @param c Context to detect UI Mode.
 * @return true when device is running in tv mode, false otherwise.
 */
public static String getDeviceType(Context c) {
    UiModeManager uiModeManager = (UiModeManager) c.getSystemService(Context.UI_MODE_SERVICE);
    int modeType = uiModeManager.getCurrentModeType();
    switch (modeType){
        case Configuration.UI_MODE_TYPE_TELEVISION:
            return "TELEVISION";
        case Configuration.UI_MODE_TYPE_WATCH:
            return "WATCH";
        case Configuration.UI_MODE_TYPE_NORMAL:
            String type = isTablet(c) ? "TABLET" : "PHONE";
            return type;
        case Configuration.UI_MODE_TYPE_UNDEFINED:
            return "UNKOWN";
        default:
            return "";
    }
}
 
Example 4
Source File: MizLib.java    From Mizuu with Apache License 2.0 6 votes vote down vote up
/**
 * Determines if the device uses navigation controls as the primary navigation from a number of factors.
 * @param context Application Context
 * @return True if the device uses navigation controls, false otherwise.
 */
public static boolean usesNavigationControl(Context context) {
    Configuration configuration = context.getResources().getConfiguration();
    if (configuration.navigation == Configuration.NAVIGATION_NONAV) {
        return false;
    } else if (configuration.touchscreen == Configuration.TOUCHSCREEN_FINGER) {
        return false;
    } else if (configuration.navigation == Configuration.NAVIGATION_DPAD) {
        return true;
    } else if (configuration.touchscreen == Configuration.TOUCHSCREEN_NOTOUCH) {
        return true;
    } else if (configuration.touchscreen == Configuration.TOUCHSCREEN_UNDEFINED) {
        return true;
    } else if (configuration.navigationHidden == Configuration.NAVIGATIONHIDDEN_YES) {
        return true;
    } else if (configuration.uiMode == Configuration.UI_MODE_TYPE_TELEVISION) {
        return true;
    }
    return false;
}
 
Example 5
Source File: FeatureSupport.java    From talkback with Apache License 2.0 5 votes vote down vote up
public static boolean isTv(Context context) {
  if (context == null) {
    return false;
  }

  UiModeManager modeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
  return ((modeManager != null)
      && (modeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION));
}
 
Example 6
Source File: Util.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns whether the app is running on a TV device.
 *
 * @param context Any context.
 * @return Whether the app is running on a TV device.
 */
public static boolean isTv(Context context) {
  // See https://developer.android.com/training/tv/start/hardware.html#runtime-check.
  UiModeManager uiModeManager =
      (UiModeManager) context.getApplicationContext().getSystemService(UI_MODE_SERVICE);
  return uiModeManager != null
      && uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}
 
Example 7
Source File: SDLActivity.java    From simpleSDL with MIT License 5 votes vote down vote up
/**
 * This method is called by SDL using JNI.
 */
public static boolean isAndroidTV() {
    UiModeManager uiModeManager = (UiModeManager) getContext().getSystemService(UI_MODE_SERVICE);
    if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
        return true;
    }
    if (Build.MANUFACTURER.equals("MINIX") && Build.MODEL.equals("NEO-U1")) {
        return true;
    }
    if (Build.MANUFACTURER.equals("Amlogic") && Build.MODEL.equals("X96-W")) {
        return true;
    }
    return false;
}
 
Example 8
Source File: SnapclientService.java    From snapdroid with GNU General Public License v3.0 5 votes vote down vote up
private void start(String host, int port) {
    Log.d(TAG, "start host: " + host + ", port: " + port);
    try {
        //https://code.google.com/p/android/issues/detail?id=22763
        if (running)
            return;
        android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);

        PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);

        UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
        if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
            Log.d(TAG, "Running on a TV Device");
            wakeLock = powerManager.newWakeLock(FULL_WAKE_LOCK, "snapcast:SnapcastFullWakeLock");
        } else {
            Log.d(TAG, "Running on a non-TV Device");
            wakeLock = powerManager.newWakeLock(PARTIAL_WAKE_LOCK, "snapcast:SnapcastPartialWakeLock");
        }

        wakeLock.acquire();

        WifiManager wm = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
        wifiWakeLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "snapcast:SnapcastWifiWakeLock");
        wifiWakeLock.acquire();
        this.host = host;
        this.port = port;
        startProcess();
    } catch (Exception e) {
        e.printStackTrace();
        if (listener != null)
            listener.onError(this, e.getMessage(), e);
        stop();
    }
}
 
Example 9
Source File: Util.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns whether the app is running on a TV device.
 *
 * @param context Any context.
 * @return Whether the app is running on a TV device.
 */
public static boolean isTv(Context context) {
  // See https://developer.android.com/training/tv/start/hardware.html#runtime-check.
  UiModeManager uiModeManager =
      (UiModeManager) context.getApplicationContext().getSystemService(UI_MODE_SERVICE);
  return uiModeManager != null
      && uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}
 
Example 10
Source File: Utils.java    From kernel_adiutor with Apache License 2.0 4 votes vote down vote up
public static boolean isTV(Context context) {
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2 && ((UiModeManager) context
            .getSystemService(Context.UI_MODE_SERVICE))
            .getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}
 
Example 11
Source File: OpenVPNService.java    From bitmask_android with GNU General Public License v3.0 4 votes vote down vote up
private boolean runningOnAndroidTV() {
    UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
    return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}
 
Example 12
Source File: Utils.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isTv(Context context) {
    return ((UiModeManager) Objects.requireNonNull(context.getSystemService(Context.UI_MODE_SERVICE)))
            .getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}
 
Example 13
Source File: OpenVPNService.java    From Cybernet-VPN with GNU General Public License v3.0 4 votes vote down vote up
private boolean runningOnAndroidTV() {
    UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
    return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}
 
Example 14
Source File: OpenVPNService.java    From EasyVPN-Free with GNU General Public License v3.0 4 votes vote down vote up
private boolean runningOnAndroidTV() {
    UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
    return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}
 
Example 15
Source File: Utils.java    From KA27 with Apache License 2.0 4 votes vote down vote up
public static boolean isTV(Context context) {
    return ((UiModeManager) context
            .getSystemService(Context.UI_MODE_SERVICE))
        .getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}
 
Example 16
Source File: AppUtils.java    From CumulusTV with MIT License 4 votes vote down vote up
public static boolean isTV(@NonNull Context context) {
    UiModeManager uiModeManager =
            (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
    return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}
 
Example 17
Source File: Utils.java    From KernelAdiutor with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isTv(Context context) {
    return ((UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE))
            .getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}
 
Example 18
Source File: SubsonicActivity.java    From Popeens-DSub with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle bundle) {


	sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
	sensorManager.registerListener(this, sensorManager.getDefaultSensor
			(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);

	UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
	if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
		// tv = true;
	}
	PackageManager pm = getPackageManager();
	if(!pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) {
		touchscreen = false;
	}

	setUncaughtExceptionHandler();
	applyTheme();
	applyFullscreen();
	super.onCreate(bundle);
	DownloadService.startService(this);
	setVolumeControlStream(AudioManager.STREAM_MUSIC);

	if(getIntent().hasExtra(Constants.FRAGMENT_POSITION)) {
		lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0);
	}

	if(preferencesListener == null) {
		preferencesListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
			@Override
			public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
				// When changing drawer settings change visibility
				switch(key) {
					case Constants.PREFERENCES_KEY_PODCASTS_ENABLED:
						setDrawerItemVisible(R.id.drawer_podcasts, false);
						break;
					case Constants.PREFERENCES_KEY_BOOKMARKS_ENABLED:
						setDrawerItemVisible(R.id.drawer_bookmarks, false);
						break;
					case Constants.PREFERENCES_KEY_ADMIN_ENABLED:
						setDrawerItemVisible(R.id.drawer_admin, false);
						break;
				}
			}
		};
		Util.getPreferences(this).registerOnSharedPreferenceChangeListener(preferencesListener);
	}



	RateThisApp.Config config = new RateThisApp.Config(30, 150);
	RateThisApp.init(config);
	RateThisApp.onCreate(this);
	RateThisApp.showRateDialogIfNeeded(this);
}
 
Example 19
Source File: Utils.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public static boolean isTelevision(Context context) {
    UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
    return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}
 
Example 20
Source File: SpecialSupport.java    From rebootmenu with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 检测是否在Android TV环境下
 *
 * @param context {@link PackageManager}
 * @return boolean
 * @see <a href="https://developer.android.com/training/tv/start/hardware.html#check-features">处理 TV 硬件 - 检查硬件功能</a>
 */
public static boolean isAndroidTV(Context context) {
    UiModeManager uiModeManager = (UiModeManager) context.getSystemService(Context.UI_MODE_SERVICE);
    return uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION;
}