Is there a way for an Android app to tell in the Java code if it is running on GoogleTV vs tablets or phones?
The following link might help you: Google TV Android Developer's Guide To optimize your app for a Google TV, just add an additional layour for large screens. However, if you want to determine the device that is currently using the app at runtime, you could try the hasSystemFeature() method. With this you can test for certain hardware features that are unique to Google TV (e.g. you could test for FEATURE_TOUCHSCREEN, as any device but Google TV has one <=> if the feature is not supported, the app is probably running on a TV).
You can ask the package manager:
/**
* Test if this device is a Google TV.
*
* See 32:00 in "Google I/O 2011: Building Android Apps for Google TV"
* http://www.youtube.com/watch?v=CxLL-sR6XfM
*
* @return true if google tv
*/
public static boolean isGoogleTV(Context context) {
final PackageManager pm = context.getPackageManager();
return pm.hasSystemFeature("com.google.android.tv");
}
Plus this manifest line:
<uses-feature android:name="com.google.android.tv" android:required="false" />
According to the oficial docs:
The recommended way to determine if your app is running on a TV device is to use the UiModeManager.getCurrentModeType() method to check if the device is running in television mode. The following example code shows you how to check if your app is running on a TV device:
public static final String TAG = "DeviceTypeRuntimeCheck";
UiModeManager uiModeManager = (UiModeManager) getSystemService(UI_MODE_SERVICE);
if (uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION) {
Log.d(TAG, "Running on a TV Device");
} else {
Log.d(TAG, "Running on a non-TV Device");
}
The following link might help you: Google TV Android Developer's Guide To optimize your app for a Google TV, just add an additional layour for large screens. However, if you want to determine the device that is currently using the app at runtime, you could try the hasSystemFeature() method. With this you can test for certain hardware features that are unique to Google TV (e.g. you could test for FEATURE_TOUCHSCREEN, as any device but Google TV has one <=> if the feature is not supported, the app is probably running on a TV).
Here's how I collect useful information for the feedback. I'm not aware if it's possible to detect type of the device (phone, vs table, vs. Google TV) but it's possible to build some sort of mapping database and match info against it
private String getDeviceInfo() {
final StringBuilder sb = new StringBuilder("\n\n---\n");
try {
sb.append("Version: ").append(getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName)
.append('\n');
} catch (final NameNotFoundException e) {
// Shouldn't happen but if did - ignore
Log.e(TAG, "failed to get app version", e);
}
sb.append("Model: ").append(Build.MODEL).append('\n');
sb.append("Brand: ").append(Build.BRAND).append('\n');
sb.append("Device: ").append(Build.DEVICE).append('\n');
sb.append("Display: ").append(Build.DISPLAY).append('\n');
sb.append("Hardware: ").append(Build.HARDWARE).append('\n');
sb.append("Manufacturer: ").append(Build.MANUFACTURER).append('\n');
sb.append("Host: ").append(Build.HOST).append('\n');
sb.append("Release: ").append(Build.VERSION.RELEASE).append('\n');
sb.append("Board: ").append(Build.BOARD).append('\n');
sb.append("Radio: ").append(Build.RADIO).append('\n');
sb.append("Product: ").append(Build.PRODUCT).append('\n');
return sb.toString();
}
© 2022 - 2024 — McMap. All rights reserved.