Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 920
bentzy Avatar asked May 06 '18 05:05

bentzy


2 Answers

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;
}

like image 54
TechnoTrancer Avatar answered Oct 17 '22 02:10

TechnoTrancer


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.

like image 29
Sahil Avatar answered Oct 17 '22 03:10

Sahil