android 悬浮窗权限申请

申请方法:

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

完美解决~~~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值