申请方法:

//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 \

完美解决~~~

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐