11

我想禁用一些功能并减少 Android Go 设备上的内存消耗。我想要一个适用于所有 Android 设备的 APK。

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

4

4 回答 4

10

这适用于我,基于预装的应用程序。

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

在极少数情况下,这些应用程序没有预装,我们会寻找Gmail GoYoutube 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;
}

于 2019-03-26T23:39:14.380 回答
4

似乎没有用于检索应用程序是否在 GO 版本上运行的直接 api。

但是您可以通过以下组合来解决此问题:

  • 基于设备内存并确定应用程序的阈值:

    private ActivityManager.MemoryInfo getAvailableMemory() {
     ActivityManager activityManager = 
    (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
    ActivityManager.MemoryInfo memoryInfo = new 
    ActivityManager.MemoryInfo();
    activityManager.getMemoryInfo(memoryInfo);
    return memoryInfo;
    }
    
  • 对于特定型号/制造商,可以采取进一步的类似步骤:

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

希望能帮助到你。

于 2018-05-06T06:23:31.703 回答
0

不,正如@chrylis指出的那样,检查版本号不会有帮助,因为有一个完整的 Android 版本具有相同的编号。

根据文档,要检查设备是否正在运行 Android Go,您可以调用

 ActivityManager.isLowRamDevice();

或者

PackageManager.hasSystemFeature("FEATURE_RAM_LOW");

true如果设备运行的是 Android Go 版本,并且false运行的是普通的 Android ,两者都会返回。

我会依赖这些 API,而不是检查其他 Android Go 版本系统应用程序(如 Gmail 的 android Go 版本),因为这些应用程序可能已被用户安装或卸载,可能会触发误报或漏报。

于 2021-12-23T10:13:36.190 回答
-2

以我的经验,ActivityManager.isLowRamDevice()相当于是一部 Android Go 手机。

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

虽然,我上次查看文档时,我认为它在任何地方都明确地说,Android Go 和 isLowRamDevice() 是等价的。

于 2020-10-22T22:13:39.113 回答