Permission Denial with Contacts in Android
<p>I'm trying to access the contacts and display them, but it won't let me, it denies me access...i already read others answsers in this website but still with the error...I already gave the permissions in a properly way.</p>

<p>this is the code:</p>

<pre><code>    TextView contactView = (TextView) findViewById(R.id.contactview);
    Cursor cursor = getContacts();

    while(cursor.moveToNext()){

        String displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME));
        contactView.append("Name: ");
        contactView.append(displayName);
        contactView.append("\n");
    }
     //End of onCreate

    private Cursor getContacts(){

    //runs the query

    Uri uri = ContactsContract.Contacts.CONTENT_URI;
    String[] projection = new String[] {ContactsContract.Contacts._ID ,ContactsContract.Contacts.DISPLAY_NAME};
    String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" + ("1") + "'";
    String[] selectionArgs = null;
    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";

    return getContentResolver().query(uri,projection,selection,selectionArgs,sortOrder);
}
</code></pre>

<p>This is the Manifest file:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pc.contentprovider"&gt;

&lt;uses-permission android:name="android.permission.READ_CONTACTS"/&gt;
&lt;uses-permission android:name="android.permission.WRITE_CONTACTS"/&gt;


&lt;application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"&gt;
    &lt;activity
        android:name=".ContactsActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar"&gt;



        &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.MAIN" /&gt;

            &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
        &lt;/intent-filter&gt;
    &lt;/activity&gt;
&lt;/application&gt;
</code></pre>

<p></p>

<p>And the Log:</p>

<pre><code>01-17 23:12:33.250 10142-10142/com.example.pc.contentprovider E/AndroidRuntime: FATAL EXCEPTION: main
                                                                            Process: com.example.pc.contentprovider, PID: 10142                            java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pc.contentprovider/com.example.pc.contentprovider.ContactsActivity}: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{5150ff8 10142:com.example.pc.contentprovider/u0a57} (pid=10142, uid=10057) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                                at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                at android.os.Looper.loop(Looper.java:148)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                             Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{5150ff8 10142:com.example.pc.contentprovider/u0a57} (pid=10142, uid=10057) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
                                                                                at android.os.Parcel.readException(Parcel.java:1599)
                                                                                at android.os.Parcel.readException(Parcel.java:1552)
                                                                                at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:3550)
                                                                                at android.app.ActivityThread.acquireProvider(ActivityThread.java:4778)
                                                                                at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2018)
                                                                                at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1468)
                                                                                at android.content.ContentResolver.query(ContentResolver.java:475)
                                                                                at android.content.ContentResolver.query(ContentResolver.java:434)
                                                                                at com.example.pc.contentprovider.ContactsActivity.getContacts(ContactsActivity.java:60)
                                                                                at com.example.pc.contentprovider.ContactsActivity.onCreate(ContactsActivity.java:25)
                                                                                at android.app.Activity.performCreate(Activity.java:6237)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                at android.os.Looper.loop(Looper.java:148) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
01-17 23:13:12.640 10142-10142/? I/Process: Sending signal. PID: 10142 SIG: 9
</code></pre>