5

有什么方法可以检测到该设备正在运行 Android Go 版本?需要确定设备是否能够SYSTEM_ALERT_WINDOWAPI 29开始提供。

根据参考资料,在API 29 GoSettings.canDrawOverlays(Context context)上将始终返回 false 。在不知道系统是否可以提供访问权限的情况下,很难解决此问题。SYSTEM_ALERT_WINDOW

4

3 回答 3

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

以下代码可在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();
    }
于 2019-10-12T05:25:27.710 回答
3

可以参考Android 11源码的实现。它仅用于ActivityManager.isLowRamDevice()检查SYSTEM_ALERT_WINDOW权限是否可用。

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));
}
于 2020-12-07T05:06:22.050 回答
2

您可以简单地查询PackageManager以检查是否安装了其中一个 Android GO 预加载应用程序,因为它们具有不同的包名称。例如:

Gmail Go 包名称:“com.google.android.gm.lite”

常规 Gmail 包名称:“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
    }
}
于 2021-03-11T09:25:57.077 回答