从Android应用中识别GoogleTv

mig*_*uel 9 android google-tv

有没有办法让Android应用程序在Java代码中告诉它是否在平板电脑或手机上运行?

Dar*_*ell 10

您可以询问包管理员:

/**
 * 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");
}
Run Code Online (Sandbox Code Playgroud)

加上这个清单行:

<uses-feature android:name="com.google.android.tv" android:required="false" />
Run Code Online (Sandbox Code Playgroud)


Pri*_*off 6

根据官方文件:

确定您的应用是否在电视设备上运行的推荐方法是使用UiModeManager.getCurrentModeType()方法检查设备是否在电视模式下运行.以下示例代码显示了如何检查您的应用是否在电视设备上运行:

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");
}
Run Code Online (Sandbox Code Playgroud)


Mar*_*iak 5

以下链接可能对您有所帮助:Google TV Android开发人员指南要优化Google TV的应用,只需为大屏幕添加额外的选择.但是,如果要在运行时确定当前正在使用该应用程序的设备,可以尝试使用hasSystemFeature()方法.通过这种方式,您可以测试Google TV独有的某些硬件功能(例如,您可以测试FEATURE_TOUCHSCREEN,因为任何设备除了Google TV都有一个<=>如果该功能不受支持,该应用可能正在电视上运行) .

  • [Here](http://code.google.com/tv/android/docs/gtv_android_features.html)是电视上不存在的更多功能.如果将它们组合在一起,您可以非常确定您的应用运行的设备类型.但我无法肯定地说出任何事情,因为我自己没有Google TV. (2认同)