权限申请清单
<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" />实现流程:
1.检查是否有该权限
2.检查是否解析受限,如果有则直接申请权限,没有则弹窗提示用户申请权限。
3.系统回调onRequestPermissionsResult反馈申请结果。
4.如果用户拒绝就弹窗提示是否跳转到设置里面的应用软件权限设置页面。
多权限申请和单权限申请类似,在申请时候申请多个而已。
List<string> requestPermissions = new ArrayList<string>(); requestPermissions.add(Manifest.permission.RECORD_AUDIO); requestPermissions.add(Manifest.permission.GET_ACCOUNTS); requestPermissions.add(Manifest.permission.READ_PHONE_STATE); requestPermissions.add(Manifest.permission.CALL_PHONE); requestPermissions.add(Manifest.permission.CAMERA); requestPermissions.add(Manifest.permission.ACCESS_FINE_LOCATION); requestPermissions.add(Manifest.permission.ACCESS_COARSE_LOCATION); requestPermissions.add(Manifest.permission.READ_EXTERNAL_STORAGE); requestPermissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); ActivityCompat.requestPermissions(MainActivity.this, requestPermissions.toArray(new String[requestPermissions.size()]), REQUEST_CONTACTS);记得在AndroidManifest里填写对应的权限。
<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" /> <uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.CALL_PHONE"/> <uses-permission android:name="android.permission.SEND_SMS"/> <uses-permission android:name="android.permission.READ_SMS"/> <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.RECORD_AUDIO"/>相关资料链接:
https://github.com/qianxiaoai/RuntimePermissionsDemo/tree/dev
谷歌Demo地址:https://github.com/googlesamples/android-RuntimePermissions
本文Demo到Linux公社资源站下载:
------------------------------------------分割线------------------------------------------
具体下载目录在 /2017年资料/1月/17日/Android 6.0动态权限申请/
------------------------------------------分割线------------------------------------------