盒子
盒子
Posts List
  1. 一. 权限中的特例,签名类权限
    1. android.permission.WRITE_SETTINGS
    2. SYSTEM_ALERT_WINDOW

app适配android 6.0(二)

这篇记录在android6.0适配过程中遇到的问题

一. 权限中的特例,签名类权限

签名类权限是google权限分类中的第三种,既不属于普通权限也不属于敏感权限,它属于signature这类权限都有共同的特征

  • 使用敏感权限检测返回 未授权
  • 发起授权请求不会弹出系统对话框
  • 提供了方法可以检测是否能正常使用

常见的签名权限:

android.permission.WRITE_SETTINGS

其它签名权限如:
android.permission.BIND_MIDI_DEVICE_SERVICE
android.permission.BIND_NFC_SERVICE
android.permission.BIND_TEXT_SERVICE
android.permission.SYSTEM_ALERT_WINDOW

更多可以参考

直接检测是否授权,返回的是未授权

int result = ContextCompat.checkSelfPermission(this , Manifest.permission.WRITE_SETTINGS);

使用敏感权限检测,不会弹出提示框

ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_SETTINGS }, 90001);

android.permission.WRITE_SETTINGS

它影响对于IMEI,MAC地址的读取等方法

WRITE_SETTINGS
Added in API level 1
Allows an application to read or write the system settings.
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_WRITE_SETTINGS. The app can check whether it has this authorization by calling Settings.System.canWrite().
Protection level: signature
Constant Value: "android.permission.WRITE_SETTINGS"

23号版本之前,仅需要在androidmanifest.xml中申明该权限即可正常使用

<uses-permission android:name="android.permission.WRITE_SETTINGS" />

23号版本后,需要申明并且还需要手动授权,

正确的使用姿势

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Settings.System.canWrite(context)) {
// Do stuff here
}
else {
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + getActivity().getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}

SYSTEM_ALERT_WINDOW

用于在所有app上面创建对话框的权限,也需要手动授权

SYSTEM_ALERT_WINDOW
Added in API level 1
String SYSTEM_ALERT_WINDOW
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"

23号版本之前,仅需要在androidmanifest.xml中申明该权限即可正常使用

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

23号版本后,需要申明并且还需要手动授权,

正确的使用姿势

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (Settings.canDrawOverlays()) {
// Do stuff here
}
else {
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
intent.setData(Uri.parse("package:" + getActivity().getPackageName()));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
支持一下
扫一扫,支持牛头码农