有什么方法可以检测到该设备正在运行 Android Go 版本?需要确定设备是否能够SYSTEM_ALERT_WINDOW
从API 29开始提供。
根据参考资料,在API 29 GoSettings.canDrawOverlays(Context context)
上将始终返回 false 。在不知道系统是否可以提供访问权限的情况下,很难解决此问题。SYSTEM_ALERT_WINDOW
有什么方法可以检测到该设备正在运行 Android Go 版本?需要确定设备是否能够SYSTEM_ALERT_WINDOW
从API 29开始提供。
根据参考资料,在API 29 GoSettings.canDrawOverlays(Context context)
上将始终返回 false 。在不知道系统是否可以提供访问权限的情况下,很难解决此问题。SYSTEM_ALERT_WINDOW
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();
}
可以参考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));
}
您可以简单地查询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
}
}