Search code examples
androidwear-osandroid-productflavorsandroid-wear-2.0

How to detect android wear 1.0 and 2.0


i have successfully made a project apk which allow the watch download the wear app. And i am trying to use that wearable code to support standalone for wear 2.0 as well - seem not much resources in the internet.

my question is how to determine if the wearable device is 1.0 or 2.0. i made use of productFlavors based on this link as follows:

android {
// Allows you to reference product flavors in your
// phone module's build.gradle file
publishNonDefault true
...
defaultConfig
{
   // This is the minSdkVersion of the Wear 1.x embedded app
   minSdkVersion 23
   ...
}
buildTypes {...}
productFlavors {
    wear1 {
      // Use the defaultConfig value
    }
    wear2 {
        minSdkVersion 25
    }
}
}

As i recalled, wear 1.0 usually collect data from phone and wear 2.0 has ability to access data via the internet. Please correct me if i am wrong.

So if the wearable is 1.0, it uses Wearable.API and sync with the phone. Otherwise, the wearable sync with cloud.

I had a look on this post which seems useful but i do not quite understand.

PackageManager pm = getApplicationContext().getPackageManager();
pm.getPackageInfo(packagename, PackageManager.GET_ACTIVITIES);

Should i set a different packagename(or applicationId) for wear2 so that i can use this method? is there any drawback when i put standalone version on play store? i suppose i have to create a new project in this way.

Please can anyone advise the best way to achieve my purpose?


Solution

  • If you want to distribute and maintain two separate APKs, then the build flavor is probably a reasonable way to go. But I would suggest that this won't be a good experience for either you or your users; it's more work for you, and it'll be confusing for them (which version do I install? why doesn't this app work after I my watch upgraded to Wear 2.0? and so on).

    My suggestion would be to put it all in one APK, and simply choose which sync technique to use at run time:

    if (Build.VERSION.SDK_INT < 24) {
        // Wear 1.x
    } else {
        // Wear 2+
    }