I am getting this error when I am trying to read contacts from phone and I included READ_CONTACTS
permission in Manifest file. And the strange thing is that it was working fine in Eclipse but when I converted my project to Gradle and run it in Android Studio I'm getting this error.
logcat says:
Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{302f069 29282:com.GP/u0a322} (pid=29282, uid=10322) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
here is the Manifest code:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<!-- Read Contacts from phone -->
<uses-permission android:name="android.permission.read_contacts" />
<uses-permission android:name="android.permission.read_phone_state" />
<uses-permission android:name="android.permission.GET_TASKS" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
Due to the Marshmallow update Requesting Permissions at Run Time the read contact permission not work. The sample code is
The sample screenshots :
I got the following source code from here
My issue was that I was using a Marshmallow emulator and that has made some changes as to how we request permissions from user. Hence it kept asking for the permissions even after adding them. http://developer.android.com/training/permissions/requesting.html
The new run-time permission scheme is used only if the app's targetSdkVersion (specified in the manifest) is 23 or higher. So, one way to avoid the issue is to make the targetSdkVersion lower than 23. See the description here:
https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous
Simply add this to your AndroidManifest.xml inside
<manifest>
: