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);}在申請的時(shí)候出現(xiàn)以下提示:由于此功能會(huì)導(dǎo)致您的手機(jī)速度變慢.....
定位源碼:android/packages/apps/Settings/src/com/android/settings/applications/manageapplications/ManageApplications.java
android/packages/apps/Settings/src/com/android/settings/Utils.java
isSystemAlertWindowEnabled 會(huì)判斷當(dāng)前設(shè)備是低內(nèi)存設(shè)備并android版本大于等于Q則關(guān)閉此功能。
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 */@UnsupportedAppUsagepublic 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
@UnsupportedAppUsagepublic static final boolean IS_DEBUGGABLE =SystemProperties.getInt("ro.debuggable", 0) == 1;在對應(yīng)的mk設(shè)置ro.config.low_ram為false:
PRODUCT_PROPERTY_OVERRIDES += \ro.config.low_ram=false \完美解決~~~
總結(jié)
以上是生活随笔為你收集整理的android 悬浮窗权限申请的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 95Echarts - 地理坐标/地图(
- 下一篇: 如何在手机上使用脚本