如何检测Android 走?
How to detect Android Go?
有什么方法可以检测到该设备是 运行 Android Go 版本吗?需要确定设备是否能够提供 SYSTEM_ALERT_WINDOW
因为 API 29.
根据参考资料,Settings.canDrawOverlays(Context context)
在 API 29 Go 上总是 return 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();
}
可以参考Android11源码的实现。
它仅使用 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
}
}
有什么方法可以检测到该设备是 运行 Android Go 版本吗?需要确定设备是否能够提供 SYSTEM_ALERT_WINDOW
因为 API 29.
根据参考资料,Settings.canDrawOverlays(Context context)
在 API 29 Go 上总是 return 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();
}
可以参考Android11源码的实现。
它仅使用 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
}
}