【发布时间】:2020-12-21 00:17:26
【问题描述】:
我想知道使用的设备是否是电视。我正在使用flutter_device_type包,但它只检测平板电脑并将任何其他设备视为手机
【问题讨论】:
我想知道使用的设备是否是电视。我正在使用flutter_device_type包,但它只检测平板电脑并将任何其他设备视为手机
【问题讨论】:
默认情况下,flutter 根据设备的最小尺寸(大于最小宽度的屏幕被视为平板电脑)检测设备,类似于以下代码:
String getDeviceType() {
final data = MediaQueryData.fromWindow(WidgetsBinding.instance.window);
return data.size.shortestSide < 600 ? 'phone' :'tablet';
}
另一方面,使用 Java/Kotlin 并基于 this documentation,您可以使用以下代码检测设备是否为 android Tv:
val uiModeManager = getSystemService(UI_MODE_SERVICE) as UiModeManager
if (uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION) {
Log.d(TAG, "Running on a TV Device")
} else {
Log.d(TAG, "Running on a non-TV Device")
}
因此,正确的选择是使用本机代码并使用 platform-channels 将其连接到颤振
【讨论】:
您可以使用device_info_plus 包来检测Android TV。
AndroidDeviceInfo 类包含 list of all the system's features,如 Android PackageManager 中所述
为了检测电视,您可以使用例如:
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
bool isTV = androidInfo.systemFeatures.contains('android.software.leanback_only')
【讨论】: