How to detect check or identify app is running on Android Go edition 8.1 Device programatically

2.9k views Asked by At

I'd like to disable some features and reduce memory consumption on Android Go Devices. I'd like to have one APK for all Android devices.

How do I detect that my app is running on an Android Go 8.1 Device? Is it sufficient to check for version 8.1 or will 8.1 version be distributed to normal Android Devices as well?

4

There are 4 answers

0
Nick On

In my experience, is ActivityManager.isLowRamDevice() is equivalent to being an Android Go phone.

boolean isAndroidGo() {
    return ((ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE))
        .isLowRamDevice();
    }
}

Although, the last time I looked in the documentation, I don't think it says anywhere, explicitly, that Android Go and isLowRamDevice() are equivalent.

2
TechnoTrancer On

This works for me, based on preinstalled Apps.

If Assistant Go or Google Go versions are installed, definitely is an Android Go device.

In rare cases that these apps didn't come preinstalled we look for Gmail Go and also Youtube Go preinstalled.

Tested on Huawei Y5 Lite with Android 8.1 (Go).


public static boolean isAndroidGoEdition(Context context) {
    final String GMAIL_GO = "com.google.android.gm.lite";
    final String YOUTUBE_GO = "com.google.android.apps.youtube.mango";
    final String GOOGLE_GO = "com.google.android.apps.searchlite";
    final String ASSISTANT_GO = "com.google.android.apps.assistant";

    boolean isGmailGoPreInstalled = isPreInstalledApp(context, GMAIL_GO);
    boolean isYoutubeGoPreInstalled = isPreInstalledApp(context, YOUTUBE_GO);
    boolean isGoogleGoPreInstalled = isPreInstalledApp(context, GOOGLE_GO);
    boolean isAssistantGoPreInstalled = isPreInstalledApp(context, ASSISTANT_GO);

    if(isGoogleGoPreInstalled | isAssistantGoPreInstalled){
        return true;
    }
    if(isGmailGoPreInstalled && isYoutubeGoPreInstalled){
        return true;
    }

    return false;
}

private static boolean isPreInstalledApp(Context context, String packageName){
    try {
        PackageManager pacMan = context.getPackageManager();
        PackageInfo packageInfo = pacMan.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
        if(packageInfo != null){
            //Check if comes with the image OS
            int mask = ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
            return (packageInfo.applicationInfo.flags & mask) != 0;
        }
    } catch (PackageManager.NameNotFoundException e) {
        //The app isn't installed
    }
    return false;
}

0
Naftoli Ost On

No, as @chrylis pointed out, checking the version number wont help because there is a full Android version with the same number.

According to the documentation, to check whether the device is running Android Go you could call either

 ActivityManager.isLowRamDevice();

or

PackageManager.hasSystemFeature("FEATURE_RAM_LOW");

Both will return true if the device is running Android Go edition, and false if it's running the regular Android.

I would rely on these APIs rather than checking for other Android Go edition system apps (like the android Go version of Gmail) because those apps may have been installed or uninstalled by the user, potentially triggering false positives or false negatives.

0
Sahil On

There doesn't seems to be direct api for retrieving whether app is running on GO version.

But you may cover the case by combination of following :

  • based on device memory and deciding on threshold value for your app:

    private ActivityManager.MemoryInfo getAvailableMemory() {
     ActivityManager activityManager = 
    (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo memoryInfo = new 
    ActivityManager.MemoryInfo();
    activityManager.getMemoryInfo(memoryInfo);
    return memoryInfo;
    }
    
  • Further similar steps can be take for particular model/manufacturer :

    String deviceName = android.os.Build.MODEL;
    String deviceMan = android.os.Build.MANUFACTURER;
    

Hope it helps.