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