Questions about Sdk>=23 's Android version permissions

Source: Internet
Author: User

In the SDK23 is the Android6.0.1 to write the call system directory Read and Write permissions program, in Androidmanifest.xml, has been configured

<android:name= "Android.permission.READ_CONTACTS"/><  android:name= "Android.permission.WRITE_CONTACTS"/>

However, the exception still occurs in the run, as follows:

Java.lang.SecurityException:Permission denial:opening provider Com.android.providers.contacts.ContactsProvider2 From Processrecord (pid=28104, uid=10176) requires Android.permission.READ_CONTACTS or android.permission.WRITE_ CONTACTS

The reason is that SDK23 has made changes to application permissions, and there are two workarounds:
① is developed using SDK22, and the Android virtual machine that runs this program or the phone's system is under 6.0.

② before using Contentresolver, add the following code to verify the permissions.
The declaration of the Requestcode:request_code_ask_permissons constant is first performed.

Final Private int Request_code_ask_permissions = 123;

Before calling Contentresolver, check the permissions

 int  haswritecontactspermisson = Checkselfpermission (Android. Manifest.permission.READ_CONTACTS);  if  (Haswritecontactspermisson!= packagemanager.permission_granted) {Requestpermissions ( new   string[] {Manifest.permission.WRITE    _contacts}, Request_code_ask_permissions);  return  ;}  //  use Contentresolver to find contact data  Cursor cursor = Getcontentresolver (). Query (ContactsContract.Contacts.CONTENT_URI, null , null , null , null ); 

On the Xiaomi phone, the results of the operation:

Questions about Sdk>=23 's Android version permissions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.