Identify GoogleTv from Android app
Asked Answered
T

4

10

Is there a way for an Android app to tell in the Java code if it is running on GoogleTV vs tablets or phones?

Trimorphism answered 2/6, 2011 at 0:25 Comment(2)
Since, at the time of this writing, we cannot write apps for Google TV, the answer is "if your Java code is running, it is not on Google TV". I recommend asking again sometime after we can write apps for Google TV.Allaround
I happen to have one of the "fishtank" devices. I'll edit the question to reflect that.Trimorphism
D
5

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).

Drover answered 2/6, 2011 at 0:41 Comment(3)
Aren't there low end trackball-only phones that also don't have a touchscreen?Trimorphism
Here are some more features that doesn't exist on TVs. If you combine them, you can be pretty sure which type of device your app is running on. But I can't say anything for sure, as I don't have a Google TV on my own.Drover
@miguel: Right now, all phones with the Android Market legitimately on them have a touchscreen, as that is required by the CDD. That does not rule out phones without the Market, phones with pirated copies of the Market, or future changes to the CDD, though.Allaround
T
10

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" />
Tabaret answered 20/7, 2011 at 19:24 Comment(0)
B
6

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");
}
Boomkin answered 13/8, 2015 at 13:56 Comment(0)
D
5

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).

Drover answered 2/6, 2011 at 0:41 Comment(3)
Aren't there low end trackball-only phones that also don't have a touchscreen?Trimorphism
Here are some more features that doesn't exist on TVs. If you combine them, you can be pretty sure which type of device your app is running on. But I can't say anything for sure, as I don't have a Google TV on my own.Drover
@miguel: Right now, all phones with the Android Market legitimately on them have a touchscreen, as that is required by the CDD. That does not rule out phones without the Market, phones with pirated copies of the Market, or future changes to the CDD, though.Allaround
I
1

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();
}
Interaction answered 2/6, 2011 at 0:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.