如何检查、检测或识别设置组件屏幕覆盖或任何可用或不可用的功能 [英] How to check, detect or identify the settings component screen overlay or any feature available or not

查看:127
本文介绍了如何检查、检测或识别设置组件屏幕覆盖或任何可用或不可用的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的安卓应用需要显示在其他应用权限之上,即屏幕覆盖权限.

My android app need display over other app permission which is screen overlay permission.

  • 设置.ACTION_MANAGE_OVERLAY_PERMISSION
  • SYSTEM_ALERT_WINDOW

在普通的 android 操作系统设备中,我可以使用此代码轻松授予权限.

In normal android OS device i can give permission easily using this code.

if (!Settings.canDrawOverlays(this) && !Constant.IsOverlayPermissionGiven) {

                Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                        Uri.parse("package:" + getPackageName()));
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
                startActivityForResult(intent, REQUEST_CODE);
                handler.postDelayed(checkSettingOn, 200);
                return false;
            } else {
                return true;
            }

但在 Android Go 版设备许可屏幕中显示此功能不可用"的消息;请注意此功能已关闭,因为它会降低您的手机速度"

But in Android Go edition device permission screen displaying the message of "This feature is not available" with the caution of "This feature has been turned off because it slows down your phone"

如何以编程方式获取有关该功能的信息是否可用?没有屏幕叠加功能的设备如何绕过权限屏幕?

How to get the information about the feature is available or not programmatically ? How to bypass the permission screen which device don't have screen overlay feature?

推荐答案

如果你阅读了 Android 11 源代码,你可以看到它只使用了 ActivityManager.isLowRamDevice() 来检查 ActivityManager.isLowRamDevice()code>SYSTEM_ALERT_WINDOW 功能是否可用

If you read the Android 11 source code, you can see that it only uses ActivityManager.isLowRamDevice() to check whether the SYSTEM_ALERT_WINDOW feature is available or not

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));
}

这篇关于如何检查、检测或识别设置组件屏幕覆盖或任何可用或不可用的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆