如何获得当前版本的Android Wear?

时间:2021-02-09 07:22:16

I want to get the Android Wear version (e.g. 1.5.0) the application is running in the same manner

我想获得Android Wear版本(例如1.5.0),应用程序以同样的方式运行

Build.VERSION.RELEASE;

does for mobile.

为移动。

1 个解决方案

#1


1  

If you want to know this to adapt your app's functionality, you're better off checking the SDK level on the device, the same as you would on an Android phone or tablet. As you probably know, you do this with Build.VERSION.SDK_INT.

如果你想知道如何调整应用程序的功能,最好在设备上检查SDK级别,就像在安卓手机或平板电脑上一样。您可能知道,这是通过Build.VERSION.SDK_INT实现的。

For example, Wear 2.0 is based on Nougat, and 1.5 on Marshmallow, so you can do a comparison like

例如,Wear 2.0是基于Nougat的,1.5是基于Marshmallow的,所以您可以进行比较。

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)

to determine if the watch is running Wear 1.x or 2.0+.

确定手表是否正在运行磨损1。x或2.0 +。

If you really need to know the Wear version number, you can get that, but it's a bit more involved:

如果你真的需要知道磨损版本号,你可以得到它,但它有点复杂:

try {
    PackageManager pkgMgr = context.getPackageManager();
    PackageInfo pkgInfo = pkgMgr.getPackageInfo("com.google.android.wearable.app", 0);
    String wearVersion = pkgInfo.versionName;
} catch (NameNotFoundException e) {
    Log.w(TAG, "Can't load PackageInfo for Android Wear app");
}

This will give you a value like 1.5.0.3505725 or 2.0.0.141602697, from which you can parse out as many digits as you're interested in.

这将为您提供一个值,比如1.5.0.3505725或2.0.141602697,您可以从中解析出所感兴趣的所有数字。

#1


1  

If you want to know this to adapt your app's functionality, you're better off checking the SDK level on the device, the same as you would on an Android phone or tablet. As you probably know, you do this with Build.VERSION.SDK_INT.

如果你想知道如何调整应用程序的功能,最好在设备上检查SDK级别,就像在安卓手机或平板电脑上一样。您可能知道,这是通过Build.VERSION.SDK_INT实现的。

For example, Wear 2.0 is based on Nougat, and 1.5 on Marshmallow, so you can do a comparison like

例如,Wear 2.0是基于Nougat的,1.5是基于Marshmallow的,所以您可以进行比较。

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)

to determine if the watch is running Wear 1.x or 2.0+.

确定手表是否正在运行磨损1。x或2.0 +。

If you really need to know the Wear version number, you can get that, but it's a bit more involved:

如果你真的需要知道磨损版本号,你可以得到它,但它有点复杂:

try {
    PackageManager pkgMgr = context.getPackageManager();
    PackageInfo pkgInfo = pkgMgr.getPackageInfo("com.google.android.wearable.app", 0);
    String wearVersion = pkgInfo.versionName;
} catch (NameNotFoundException e) {
    Log.w(TAG, "Can't load PackageInfo for Android Wear app");
}

This will give you a value like 1.5.0.3505725 or 2.0.0.141602697, from which you can parse out as many digits as you're interested in.

这将为您提供一个值,比如1.5.0.3505725或2.0.141602697,您可以从中解析出所感兴趣的所有数字。