Check if a device is running Android-Things
Asked Answered
D

2

7

Is it possible to perform a runtime check to see if a device is running Android-Things?

Darlington answered 24/5, 2017 at 17:50 Comment(4)
What is the specific, um, thing that you want to do differently on a Thing than on another Android device? For example, if you want to use Things-specific API classes, use Class.forName() to see if they exist.Bipod
Well, i'm trying to see if i could have the same app for Android also run in android-things and i might want to perform automatic actions on an unmanaged android-things device while asking for manual input on a regular android device.Darlington
I would argue that your decision-making criteria should not be "is it a Thing?", but instead "do we have a screen?", or something like that. Android Things can have screens and input devices, where the user might be interested in providing manual input.Bipod
You are right. I will consider implementing that way. Although it seems weird that such a small convenience method is missing from the things SDK.Darlington
U
12

You can query the PackageManager for FEATURE_EMBEDDED, which is implemented by all Android Things devices:

public boolean isThingsDevice(Context context) {
    final PackageManager pm = context.getPackageManager();
    return pm.hasSystemFeature(PackageManager.FEATURE_EMBEDDED);
}

This constant was recently added in the Android O Preview SDK. Until an Android Things preview based on O is released, you may need to use the literal name of the constant: android.hardware.type.embedded

Underage answered 25/5, 2017 at 3:20 Comment(1)
Thanks! I was looking for something like this.Darlington
A
1

Any apk you make with AndroidThings will be uploaded to the IoT console not to the play store.

Therefore I would recommend if you want a single codebase that you use Gradle Flavors and a flag. This means you will build two separate APK's - rather than doing a "what platform am I on" check at runtime.

This will ensure your APK has the smallest size on both memory constrained separate platforms. (For instance the flavor of Google Play Services that is used on Android Things is a slimmed down version of what is available for general Android apps). Android Things supports a subset of the Google APIs for Android. The linked table breaks down API support in Android Things.

Asshur answered 24/5, 2017 at 20:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.