申请方法:
//AndroidManifest.xml添加
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent();
intent.setAction(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
startActivity(intent);
}
在申请的时候出现以下提示:由于此功能会导致您的手机速度变慢.....
定位源码:android/packages/apps/Settings/src/com/android/settings/applications/manageapplications/ManageApplications.java
android/packages/apps/Settings/src/com/android/settings/Utils.java
isSystemAlertWindowEnabled 会判断当前设备是低内存设备并android版本大于等于Q则关闭此功能。
isLowRamDevice是通过属性ro.config.low_ram
或debug模式属性判断,源码:android/frameworks/base/core/java/android/app/ActivityManager.java
private static final boolean DEVELOPMENT_FORCE_LOW_RAM =
SystemProperties.getBoolean("debug.force_low_ram", false);
/**
* 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();
}
/** @hide */
@UnsupportedAppUsage
public static boolean isLowRamDeviceStatic() {
return RoSystemProperties.CONFIG_LOW_RAM ||
(Build.IS_DEBUGGABLE && DEVELOPMENT_FORCE_LOW_RAM);
}
android/frameworks/base/core/java/com/android/internal/os/RoSystemProperties.java
public static final boolean CONFIG_LOW_RAM =
SystemProperties.getBoolean("ro.config.low_ram", false);
android/frameworks/base/core/java/android/os/Build.java
@UnsupportedAppUsage
public static final boolean IS_DEBUGGABLE =
SystemProperties.getInt("ro.debuggable", 0) == 1;
在对应的mk设置ro.config.low_ram
为false:
PRODUCT_PROPERTY_OVERRIDES += \
ro.config.low_ram=false \
完美解决~~~