我如何能确定我是否在Android Wear或不正在运行?或不、正在运行、Android、Wear

由网友(浅抹dē烟薰妆)分享简介:我有一个手机和Android的工作室穿模块,它们都使用的是核心code-基地......在核心 - code,我怎么能确定是我的code在移动模块的磨损运行?我应该使用屏幕大小?I have a mobile and wear module in Android Studio and they are both...

我有一个手机和Android的工作室穿模块,它们都使用的是核心code-基地......在核心 - code,我怎么能确定是我的code在移动模块的磨损运行?我应该使用屏幕大小?

I have a mobile and wear module in Android Studio and they are both using a 'core' code-base...in that core-code, how could I determine whether my code is running on a 'wear' of 'mobile' module? Should i use screen size?

推荐答案

虽然这不是正式文件(据我所知),你可以判断设备是否是手表或手持设备通过调用之一:

Though this isn't officially documented (that I know of) you can determine whether the device is a watch or handheld by invoking either:

getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);

或使用:

Configuration config = getResources().getConfiguration();
boolean isWatch = (config.uiMode & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_WATCH;

我已经测试了,他们回到在我的测试设备磨损(摩托车360)真假一台Nexus 5的手机。

I've tested both and they return true in my test Wear device (Moto 360) and false in a Nexus 5 phone.

(我发现他们通过浏览 API差异报告API级别4.4W(20)虽然不能保证,这些应该更加面向未来的比检查非供应情况的其他特征,因为这些可能只是暂时的限制)。

(I found them by browsing the API Differences Report for API level 4.4W (20). Though not guaranteed, these should be more future-proof than checking for the non-availabilty of other features, as those might be just temporary limitations).

阅读全文

相关推荐

最新文章