-1

I am attempting to access and retrieve all of the phone numbers for a particular contact (not all contacts), and am continuously running into the same permissions error despite having properly added necessary permissions.

  1. I restarted Android Studio
  2. I checked the syntax of my declaration
  3. I checked for duplicate activity declarations

Yet the problem persists.

My log is shown here:

java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/data/phones from pid=30288, uid=10127 requires android.permission.READ_CONTACTS, or grantUriPermission()

And apparently the permission issue occurs at the indicated line in this setup:

if (reqCode == REQUEST_CONTACT_PICKER) {
        if (resultCode == Activity.RESULT_OK) {
            if (data != null) {
                Uri contactData = data.getData();

                try {

                    String id = contactData.getLastPathSegment();
                    Cursor phoneCur = getContentResolver()
                            .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, //----- -This one- ---------
                                    null,
                                    ContactsContract.CommonDataKinds.Phone.CONTACT_ID
                                            + " = ?", new String[] { id },
                                    null);

For reference here is my manifest, the issue is occurring in Text_main.

<?xml version="1.0" encoding="utf-8"?>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <uses-permission android:name="android.permission.READ_CONTACTS"/>
    <activity
        android:name=".StartMenu"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Text_main"
        android:label="@string/title_activity_text_main" >
    </activity>
    <activity
        android:name=".Call_main"
        android:label="@string/title_activity_call_main" >
    </activity>
</application>

I am probably making a stupid and/or beginner's error as I am mostly splicing snippets (I am out of my basic comfort zone). I appreciate any help and/or constructive criticism.

By the way my code for retrieving the contacts was adapted from the top answer posted here: All phone numbers of one contact for startActivityForResult

Community
  • 1
  • 1
William Brun
  • 353
  • 2
  • 17

1 Answers1

3

<uses-permission> needs to be an immediate child of <manifest>, as a peer to <application>. It cannot be a child of <application>.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    @WilliamBrun: You aren't alone. This is a fairly common problem, which is why [I have suggested that the tools point it out](https://code.google.com/p/android/issues/detail?id=128423). – CommonsWare Feb 16 '15 at 16:29
  • That would be very beneficial. Especially since to the untrained eye these are so difficult to spot. I saw that the permission had been declared properly, and that there were no errors otherwise, and assumed the problem lay elsewhere. Hopefully they make this change. – William Brun Feb 16 '15 at 16:33