I'm working on a simple app that browses through the user's contacts. Unfortunately I keep getting the following error:
java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.HtcContactsProvider2 uri content://com.android.contacts/contacts from pid=27455, uid=10171 requires android.permission.READ_CONTACTS
My manifest file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.helloMaps"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="true">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".MapsActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I'm trying to look at my contacts by:
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null, null, null, null);
I've tried to add <uses-permission android:name="android.permission.READ_CONTACTS" />
or android:permission="android.permission.READ_CONTACTS"
to <application>
or <activity>
, but both didn't work.
I'm running out of options, does anybody know what I'm missing here?
App permissions help support user privacy by protecting access to the following: Restricted data, such as system state and a user's contact information. Restricted actions, such as connecting to a paired device and recording audio.
The Android manifest file helps to declare the permissions that an app must have to access data from other apps. The Android manifest file also specifies the app's package name that helps the Android SDK while building the app.
the <uses-permission>
should be contained in the <manifest>
element. See Structure of the Manifest File. So trying putting it into <application>
or <activity>
, won't work. Desperation move: try to move <uses-sdk>
before <application>
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
Also if you can test without the other permissions, remove them.
EDIT: Can you please check if this is your TOP line in your manifest file:
<?xml version="1.0" encoding="utf-8"?>
I was totally stuck on this until I read this article about how permissions are handled starting with SDK 23. The critical hint:
If the application's targetSdkVersion is set to less than 23. It will be assumed that application is not tested with new permission system yet and will switch to the same old behavior: user has to accept every single permission at install time and they will be all granted once installed !
I opened up my gradle.build
file and changed targetSdkVersion 23
to targetSdkVersion 22
, and now everything works great! I'll eventually find time to build in the new permissions system and switch back to targetSdkVersion 23
, which is probably the more correct answer. This is a temporary shortcut.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With