English 中文(简体)
Identify GoogleTv from Android app
原标题:

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");
}

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("

---
");
    try {
        sb.append("Version: ").append(getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName)
                .append( 
 );
    } 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( 
 );
    sb.append("Brand: ").append(Build.BRAND).append( 
 );
    sb.append("Device: ").append(Build.DEVICE).append( 
 );
    sb.append("Display: ").append(Build.DISPLAY).append( 
 );
    sb.append("Hardware: ").append(Build.HARDWARE).append( 
 );
    sb.append("Manufacturer: ").append(Build.MANUFACTURER).append( 
 );
    sb.append("Host: ").append(Build.HOST).append( 
 );
    sb.append("Release: ").append(Build.VERSION.RELEASE).append( 
 );
    sb.append("Board: ").append(Build.BOARD).append( 
 );
    sb.append("Radio: ").append(Build.RADIO).append( 
 );
    sb.append("Product: ").append(Build.PRODUCT).append( 
 );
    return sb.toString();
}




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签