如何检测检查或识别应用程序正在以编程方式在Android Go 8.1版设备上运行

时间:2018-05-06 05:54:03

标签: java android android-8.1-oreo android-go

我想在Android Go设备上禁用某些功能并减少内存消耗。我想为所有Android设备安装一个APK。

如何检测我的应用是否在Android Go 8.1设备上运行? 是否足以检查版本8.1或8.1版本是否也会分发到普通的Android设备?

3 个答案:

答案 0 :(得分:3)

似乎没有直接api来检索app是否在GO版本上运行。

但您可以通过以下方式来涵盖案件:

  • 根据设备内存并确定应用的阈值:

    populate
  • 特定型号/制造商可采取进一步类似的步骤:

    private ActivityManager.MemoryInfo getAvailableMemory() {
     ActivityManager activityManager = 
    (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo memoryInfo = new 
    ActivityManager.MemoryInfo();
    activityManager.getMemoryInfo(memoryInfo);
    return memoryInfo;
    }
    

希望它有所帮助。

答案 1 :(得分:0)

这对我有效,基于预先安装的应用。

如果安装了 Assistant Go Google Go 版本,则肯定是Android Go设备。

在极少数情况下没有预先安装这些应用程序,我们会寻找 Gmail Go Youtube Go

在带有Android 8.1(Go)的华为Y5 Lite上进行了测试。


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

答案 2 :(得分:-1)

ActivityManager.isLowRamDevice()等同于成为Android Go手机吗?我认为是的,但文档尚不清楚。也许有人可以看看Android源代码并告诉我们??

ActivityManager activityManager = (ActivityManager) 
context.getSystemService(Context.ACTIVITY_SERVICE);
if (activityManager != null) {
  return activityManager.isLowRamDevice();
}