功能简介
华为在自己的审核机制里面加入了新的要求,在申请权限的时候附加更详细的介绍信息。并且附带了一张示例
[]
方案
一般来说实现弹窗有以下几种常见方式:toast
,snackbar
,dialog
,windowManager.addView
。能够显示在其他应用上的显示方式只有toast
和悬浮窗这两种,由于权限限制,悬浮窗需要向用户请求相应权限,并跳转系统设置页面做修改,因此比较难以获得。因而本文重点讨论toast和dialog等形式的实现异同
toast
snackbar
dialog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16//dialog with system permission
val dialog = PermissionTipsDialog(context,tips)
val attributes = dialog.window?.attributes
dialog.window?.decorView?.setPadding(0, 0, 0, 0)
attributes?.gravity = Gravity.TOP
attributes?.width = WindowManager.LayoutParams.MATCH_PARENT
attributes?.height = WindowManager.LayoutParams.WRAP_CONTENT
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
attributes?.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
}else{
attributes?.type = WindowManager.LayoutParams.TYPE_PRIORITY_PHONE
}
dialog.window?.attributes = attributes
dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
dialog.show()增加以下权限
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
在Android O后该权限被控制,需要申请悬浮窗权限
1
2
3Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
intent.setData(Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 100);wms addview