简体   繁体   English

如何检测 Android Go?

[英]How to detect Android Go?

Is there any way to detect that device is running Android Go edition?有什么方法可以检测到该设备正在运行 Android Go 版本? Need to determine if device is capable of providing SYSTEM_ALERT_WINDOW since API 29 .需要确定设备是否能够提供自SYSTEM_ALERT_WINDOW 29以来的 SYSTEM_ALERT_WINDOW。

According the reference, Settings.canDrawOverlays(Context context) will always return false on API 29 Go .根据参考, Settings.canDrawOverlays(Context context)将始终在API 29 Go上返回 false 。 Without knowing if the system is possible to give access to SYSTEM_ALERT_WINDOW it's hard to work around the case.在不知道系统是否可以授予对SYSTEM_ALERT_WINDOW的访问权限的情况下,很难解决此问题。

ActivityManager am = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
am.isLowRamDevice();

The following code is available in ActivityManager.java以下代码在ActivityManager.java中可用

    /**
     * Returns true if this is a low-RAM device.  Exactly whether a device is low-RAM
     * is ultimately up to the device configuration, but currently it generally means
     * something with 1GB or less of RAM.  This is mostly intended to be used by apps
     * to determine whether they should turn off certain features that require more RAM.
     */
    public boolean isLowRamDevice() {
        return isLowRamDeviceStatic();
    }

You can refer to the implementation of the Android 11 source code.可以参考Android 11源码的实现。 It only uses ActivityManager.isLowRamDevice() to check if the SYSTEM_ALERT_WINDOW permission is available.它只使用ActivityManager.isLowRamDevice()来检查SYSTEM_ALERT_WINDOW权限是否可用。

packages\apps\Settings\src\com\android\settings\Utils.java packages\apps\Settings\src\com\android\settings\Utils.java

/**
 * Returns true if SYSTEM_ALERT_WINDOW permission is available.
 * Starting from Q, SYSTEM_ALERT_WINDOW is disabled on low ram phones.
 */
public static boolean isSystemAlertWindowEnabled(Context context) {
    // SYSTEM_ALERT_WINDOW is disabled on on low ram devices starting from Q
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    return !(am.isLowRamDevice() && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q));
}

You can simply query PackageManager to check if one of the Android GO preloaded apps is installed, as they have different package names.您可以简单地查询PackageManager以检查是否安装了 Android GO 预加载应用程序之一,因为它们具有不同的 package 名称。 For example:例如:

Gmail Go package name: "com.google.android.gm.lite" Gmail Go package 名称:“com.google.ZC31B32364CE19CA8FCD150A417ECCE”。

Regular Gmail package name: "com.google.android.gm"常规 Gmail package 名称:“com.google.android.gm”

fun isGoDevice(): Boolean {
    val GMAIL_GO_PACKAGE_NAME = "com.google.android.gm.lite"
    val packageManager = context.getPackageManager()
    return try {
        packageManager.getPackageInfo(GMAIL_GO_PACKAGE_NAME, 0)
        true
    } catch (e: PackageManager.NameNotFoundException) {
        false
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM