Android6.0 创建TYPE_SYSTEM_ALERT级别的弹出框方法

243 篇文章 2 订阅
17 篇文章 0 订阅

突然发现在android6之前的版本都是可以弹出系统级别的dialog, 但是到了6.0就不行了, 搜索发现官方文档有下面说明:

Allows an app to create windows using the type TYPE_SYSTEM_ALERT, shown on top of all other apps. Very few apps should use this permission; these windows are intended for system-level interaction with the user.

Note: If the app targets API level 23 or higher, the app user must explicitly grant this permission to the app through a permission management screen. The app requests the user's approval by sending an intent with action ACTION_MANAGE_OVERLAY_PERMISSION. The app can check whether it has this authorization by calling Settings.canDrawOverlays().

Protection level: signature

Constant Value: "android.permission.SYSTEM_ALERT_WINDOW"

 

首先检查下有没有权限绘出系统的级别的对话框, 有可以直接画出, 没有的话需要发个intent让用户授权, 具体实现代码如下:

if (Build.VERSION.SDK_INT >= 23) {
   if(!Settings.canDrawOverlays(this)) {
       Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
       intent.setData(Uri.parse("package:" + getPackageName()));
       startActivity(intent);
       return;
   } else {
   //绘ui代码, 这里说明6.0系统已经有权限了
   }
} else {
   //绘ui代码,这里android6.0以下的系统直接绘出即可
}




转自:http://www.enjoydiy.com/3554.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值