android 6.0 权限管理的学习资料和使用例子
来源:互联网 发布:呼和浩特软件招聘信息 编辑:程序博客网 时间:2024/06/11 01:05
善意的主把这事也告诉了android小组,当我们在targetSdkVersion 低于23的app调用一个需要权限的函数时,这个权限如果被用户取消授权了的话,不抛出异常。但是他将啥都不干,结果导致函数返回值是null或者0.
警告:现在你在android studio新建项目,targetSdkVersion 会自动设置为 23。如果你还没支持新运行时权限,我建议你首先把targetSdkVersion 降级到22
Table 1. Permissions and permission groups.
android.permission-group.CALENDAR
android.permission.READ_CALENDAR
android.permission.WRITE_CALENDAR
android.permission-group.CAMERA
android.permission.CAMERA
android.permission-group.CONTACTS
android.permission.READ_CONTACTS
android.permission.WRITE_CONTACTS
android.permission.GET_ACCOUNTS
android.permission-group.LOCATION
android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_COARSE_LOCATION
android.permission-group.MICROPHONE
android.permission.RECORD_AUDIO
android.permission-group.PHONE
android.permission.READ_PHONE_STATE
android.permission.CALL_PHONE
android.permission.READ_CALL_LOG
android.permission.WRITE_CALL_LOG
com.android.voicemail.permission.ADD_VOICEMAIL
android.permission.USE_SIP
android.permission.PROCESS_OUTGOING_CALLS
android.permission-group.SENSORS
android.permission.BODY_SENSORS
android.permission-group.SMS
android.permission.SEND_SMS
android.permission.RECEIVE_SMS
android.permission.READ_SMS
android.permission.RECEIVE_WAP_PUSH
android.permission.RECEIVE_MMS
android.permission.READ_CELL_BROADCASTS
android.permission-group.STORAGE
android.permission.READ_EXTERNAL_STORAGE
android.permission.WRITE_EXTERNAL_STORAGE
requestPermissions()
.,提示用户,让用户不会感到困惑ActivityCompat.OnRequestPermissionsResultCallback
PermissionChecker
class, which provides several static utility methods for apps that use IPC to provide services for other apps. For example,PermissionChecker.checkCallingPermission()
checks whether an IPC made by a particular package has a specified permission.requestPermissions()
的一些说明:requestPermissions()
method, the system shows a standard dialog box to the user.requestPermissions()
, as described in Explain why the app needs permissions.requestPermissions()
时,系统会显示一个获取权限的提示对话框,当前应用不能配置和修改这个对话框,requestPermissions()
之前处理。shouldShowRequestPermissionRationale()
的一些说明:To help find the situations where you need to provide extra explanation, the system provides theshouldShowRequestPermissionRationale()
method.
This method returns true
if the app has requested this permission previously and the user denied the request.
That indicates that you should probably explain to the user why you need the permission.
If the user turned down the permission request in the past and chose the Don't ask again option in the permission request system dialog, this method returns false
.
The method also returns false
if the device policy prohibits the app from having that permission.
1. 第一次请求权限时,用户拒绝了,下一次:shouldShowRequestPermissionRationale()
返回 true,应该显示一些为什么需要这个权限的说明
2.第二次请求权限时,用户拒绝了,并选择了“不在提醒”的选项时:shouldShowRequestPermissionRationale()
返回 false
3. 设备的策略禁止当前应用获取这个权限的授权:shouldShowRequestPermissionRationale()
返回 false
注意:上面的:第二次请求权限时,才会有“不在提醒”的选项,如果用户一直拒绝,并没有选择“不在提醒”的选项,下次请求权限时,会继续有“不在提醒”的选项
shouldShowRequestPermissionRationale()
的方法说明:
Gets whether you should show UI with rationale for requesting a permission.
You should do this only if you do not have the permission and the context in which the permission is requested does not clearly communicate to the user what would be the benefit from granting this permission.
For example, if you write a camera app, requesting the camera permission would be expected by the user and no rationale for why it is requested is needed. If however, the app needs location for tagging photos then a non-tech savvy user may wonder how location is related to taking photos. In this case you may choose to show UI with rationale of requesting this permission.
根据方法说明:
显示权限说明:是根据你的应用中使用的权限分类来的:
1.用户容易知道应用需要获取的权限:如一个拍照应用,需要摄像头的权限,是很正常,不用提示。
2.一些用户感觉困惑的一些权限:如:分享图片,还需要获取位置的权限,这个需要提示用户:为什么需要这个权限。
参考:
处理 “不再提醒”
如果用户拒绝某授权。下一次弹框,用户会有一个“不再提醒”的选项的来防止app以后继续请求授权。
如果这个选项在拒绝授权前被用户勾选了。下次为这个权限请求requestPermissions时,对话框就不弹出来了,结果就是,app啥都不干。这将是很差的用户体验,用户做了操作却得不到响应。这种情况需要好好处理一下。在请求requestPermissions前,
我们需要检查是否需要展示请求权限的提示通过activity的shouldShowRequestPermissionRationale,代码如下:
final private int REQUEST_CODE_ASK_PERMISSIONS = 123;
private void insertDummyContactWrapper() {
int hasWriteContactsPermission = checkSelfPermission(Manifest.permission.WRITE_CONTACTS);
if
(hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) {
//TODO
if
(!shouldShowRequestPermissionRationale(Manifest.permission.WRITE_CONTACTS)) {
showMessageOKCancel(
"You need to allow access to Contacts"
,
new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
requestPermissions(
new
String[] {Manifest.permission.WRITE_CONTACTS},
REQUEST_CODE_ASK_PERMISSIONS);
}
});
return
;
}
requestPermissions(
new
String[] {Manifest.permission.WRITE_CONTACTS},
REQUEST_CODE_ASK_PERMISSIONS);
return
;
//TODO
}
insertDummyContact();
}
private void showMessageOKCancel(String message, DialogInterface.OnClickListener okListener) {
new
AlertDialog.Builder(MainActivity.
this
)
.setMessage(message)
.setPositiveButton(
"OK"
, okListener)
.setNegativeButton(
"Cancel"
,
null
)
.create()
.show();
}
Currently, the following permissions are classified as PROTECTION_NORMAL
:
android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_NOTIFICATION_POLICY
android.permission.ACCESS_WIFI_STATE
android.permission.ACCESS_WIMAX_STATE(新文档没有)
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN
android.permission.BROADCAST_STICKY
android.permission.CHANGE_NETWORK_STATE
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.CHANGE_WIMAX_STATE(新文档没有)
android.permission.DISABLE_KEYGUARD
android.permission.EXPAND_STATUS_BAR
android.permission.FLASHLIGHT
android.permission.GET_PACKAGE_SIZE
android.permission.INTERNET
android.permission.KILL_BACKGROUND_PROCESSES
android.permission.MODIFY_AUDIO_SETTINGS
android.permission.NFC
android.permission.READ_SYNC_SETTINGS
android.permission.READ_SYNC_STATS
android.permission.RECEIVE_BOOT_COMPLETED
android.permission.REORDER_TASKS
android.permission.REQUEST_INSTALL_PACKAGES
android.permission.SET_TIME_ZONE
android.permission.SET_WALLPAPER
android.permission.SET_WALLPAPER_HINTS
android.permission.SUBSCRIBED_FEEDS_READ
(新文档没有)
android.permission.TRANSMIT_IR
android.permission.USE_FINGERPRINT
android.permission.VIBRATE
android.permission.WAKE_LOCK
android.permission.WRITE_SYNC_SETTINGS
com.android.alarm.permission.SET_ALARM
com.android.launcher.permission.INSTALL_SHORTCUT
com.android.launcher.permission.UNINSTALL_SHORTCUT
Table 1. Permissions and permission groups.
android.permission-group.CALENDAR
android.permission.READ_CALENDAR
android.permission.WRITE_CALENDAR
android.permission-group.CAMERA
android.permission.CAMERA
android.permission-group.CONTACTS
android.permission.READ_CONTACTS
android.permission.WRITE_CONTACTS
android.permission.GET_ACCOUNTS
android.permission-group.LOCATION
android.permission.ACCESS_FINE_LOCATION
android.permission.ACCESS_COARSE_LOCATION
android.permission-group.MICROPHONE
android.permission.RECORD_AUDIO
android.permission-group.PHONE
android.permission.READ_PHONE_STATE
android.permission.CALL_PHONE
android.permission.READ_CALL_LOG
android.permission.WRITE_CALL_LOG
com.android.voicemail.permission.ADD_VOICEMAIL
android.permission.USE_SIP
android.permission.PROCESS_OUTGOING_CALLS
android.permission-group.SENSORS
android.permission.BODY_SENSORS
android.permission-group.SMS
android.permission.SEND_SMS
android.permission.RECEIVE_SMS
android.permission.READ_SMS
android.permission.RECEIVE_WAP_PUSH
android.permission.RECEIVE_MMS
android.permission.READ_CELL_BROADCASTS
android.permission-group.STORAGE
android.permission.READ_EXTERNAL_STORAGE
android.permission.WRITE_EXTERNAL_STORAGE
- Use the adb tool to manage permissions from the command line:
- List permissions and status by group: 这个只是列出设备的所有的危险权限,并没有命令来显示某个应用的权限的许可情况(这点不好)
$ adb shell pm list permissions -d -g
- Grant or revoke one or more permissions:
$ adb shell pm [grant|revoke] <permission-name> ...
- List permissions and status by group: 这个只是列出设备的所有的危险权限,并没有命令来显示某个应用的权限的许可情况(这点不好)
- Analyze your app for services that use permissions.
下面是一些可以使用的命令:参考:http://blog.csdn.net/commonslok/article/details/8150018
adb -s emulator-5554 shell pm list permissions -d -g :列出设备emulator-5554上所有的分组危险权限(-d:表示危险权限 -g:表示分组)
adb -s emulator-5554 shell pm list permissions -g :列出设备emulator-5554上所有的分组权限(-g:表示分组):包括分组危险权限+没有分组的权限adb -s emulator-5554 shell pm list permissions :列出设备emulator-5554上所有的权限adb -s emulator-5554 shell pm list permissions -d -g -f :(-f:表示显示权限的详情)-s emulator-5554 :表示指定设备名称:emulator-5554(可以通过 adb devices来得到设备的列表)
adb -s emulator-5554 shell pm grant permissions.dispatcher.sample android.permission.CAMERA : 许可权限
上面:
- android 6.0 权限管理的学习资料和使用例子
- android 6.0 权限管理的学习资料和使用例子
- android 权限管理的使用
- Android权限使用(网络收集的资料)
- Android权限管理PermissionsDispatcher2.3.2使用+原生6.0权限使用
- 关于android安卓的wifi功能使用需要申请的权限和管理类
- matplotlib 使用和学习的资料
- Android学习之扩展android的权限管理
- android 权限管理PermissionDispatcher使用
- android 6.0权限管理
- Android 6.0权限管理
- Android 6.0权限管理
- android 6.0权限管理
- Android 6.0 权限管理
- Android 6.0 权限管理
- Android 6.0 权限管理
- android 6.0 权限管理
- android 6.0权限管理
- 图像滤镜艺术---漫画滤镜
- 图像滤镜艺术---LOMO Filter
- 体验复杂度 --两种排序算法的运行时间
- Android 获取状态栏高度
- 用gulp amd-optimize插件构建requriejs模块
- android 6.0 权限管理的学习资料和使用例子
- hdU 5024
- 日期的格式化//SimpleDateFormat的用法
- 解决UICollectionView内容填充不满无法下拉的问题
- 29个你必须知道的Linux命令
- #1051 : 补提交卡
- Ubuntu下安装samba步骤
- c malloc calloc realloc
- Openmesh函数库设计及与CGAL的对比