2

Our Android app works on regular devices as well as wearable devices such as Google Glass, etc. I need to add additional functionality if the app is running on a wearable. Is there an API to check if the device is a wearable or not? Regards.

Peter
  • 11,260
  • 14
  • 78
  • 155
  • 3
    Given elastic, Velcro(TM), and glue, I can make any phone or tablet a wearable. "Wearable" is more of a marketing moniker than it is a technical statement. You can detect that you are running on a watch via `PackageManager`, `hasSystemFeature()`, and `FEATURE_WATCH`. Given that [the documentation](https://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_WATCH) for `FEATURE_WATCH` has "A watch here is defined to be a device worn on the body, perhaps on the wrist", it is possible that it will work for you. – CommonsWare Sep 06 '16 at 19:01
  • I am not sure, but can't you check the resolution and decide. For example if resolution is 280x280 or 320x320. – Akshay Shinde Sep 06 '16 at 19:03
  • Thank you for your comment. +1 for Velcro/glue part. – Peter Sep 08 '16 at 00:04
  • See answer [here](http://stackoverflow.com/a/22060896/2382438) to detect if app is running on Google Glass. – bplpu Feb 20 '17 at 12:07
  • The system feature way from @CommonsWare should be the accepted answer! – BoD Feb 26 '17 at 16:28

3 Answers3

1

Wearables can be detected using resource qualifiers using the uimode :

  1. In your project's res/values/bool.xml file, create a boolean resource with a value of false, ex: <bool name="isawatch">false</bool>
  2. Create a new folder in res, called values-wear,
  3. And create another bool.xml file with boolean resource of the same name with a true value, <bool name="isawatch">true</bool>

Altogether,

res/values/bool.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="isawearable">false</bool>
</resources>

res/values-wear/bool.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="isawearable">true</bool>
</resources>

and now you should be able to call context.getResources().getBoolean(R.id.isawearable) for your app needs.

As a plus, you can find out other available app qualifiers in the android documentation table listed here, https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources

HTHS!

petey
  • 16,914
  • 6
  • 65
  • 97
0

If the app is on a watch, the watch probably is connected to a phone. Use the Wearable NodeAPI to detect the phone. This doesn't guarantee that if the device is not connected, it's not a watch. But then, just assume, the app should work properly on a watch, as long as it doesn't use too much memory.

Also, a watch doesn't have wifi (afaik), most phones do. Check wifi. Then decide "if no node connected, and we have wifi, it's safe to assume we're on a phone".

Again, for the working of the app it shouldn't really matter. I accidentally installed my phone app on my watch, it worked well, beit terribly slow.

Christine
  • 5,617
  • 4
  • 38
  • 61
0

You can figure out your android app is running on which OS Build, Product, Device etc. by using the android.os.Build class.

Eg: You can detect if your app is running on google glass(API 19) by this:

if(Build.VERSION.SDK_INT==Build.VERSION_CODES.KITKAT){
    Log.e("SDK_INT",""+Build.VERSION.SDK_INT);
    Log.e("MODEL",""+Build.MODEL);
    Log.e("DEVICE",""+Build.DEVICE);
    Log.e("TYPE",""+Build.TYPE);
    Log.e("HARDWARE",""+Build.HARDWARE);
    Log.e("BRAND",""+Build.BRAND);
    Log.e("DISPLAY",""+Build.DISPLAY);
    Log.e("MANUFACTURER",""+Build.MANUFACTURER);
    Log.e("PRODUCT",""+Build.PRODUCT);
    } else {
    Log.e("Other",""+Build.VERSION.SDK_INT);
    }

Log Results

09-13 17:58:42.835 24240-24240/com.example.myxlab.beyondartest E/SDK_INT: 19
09-13 17:58:42.835 24240-24240/com.example.myxlab.beyondartest E/MODEL: Glass 1
09-13 17:58:42.835 24240-24240/com.example.myxlab.beyondartest E/DEVICE: glass-1

Same goes for watches (API 20).