title: Application was crashed in managedQuery line in android studio
body: <p>I have coded an application that contains an list that present contact information.</p>
  
  <p>Application code is as follow:</p>
  
  <pre><code>public class MainActivity extends ListActivity {
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Cursor mCursor=getContacts();
          startManagingCursor(mCursor);
          ListAdapter adapter=new SimpleCursorAdapter(this,
                  android.R.layout.two_line_list_item,
                  mCursor, new String[]{ContactsContract.Contacts._ID,
                                      ContactsContract.Contacts.DISPLAY_NAME},
                  new int[]{android.R.id.text1, android.R.id.text2});
          setListAdapter(adapter);
      }
  
      private Cursor getContacts(){
          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";
          Cursor out=managedQuery(uri, projection, selection, selectionArgs, sortOrder);
          return out;
      }
  }
  </code></pre>
  
  <p>but application was crashed at <code>managedQuery</code> line.</p>
  
  <p>I add also <code>READ_CONTACTS</code> permission to the manifest file.</p>
  
  <p>What is wrong?</p>
  
  <p><strong>Edited:</strong></p>
  
  <p>Here is logcat data:</p>
  
  <blockquote>
  <pre><code>--------- beginning of crash
  </code></pre>
    
    <p>08-18 17:36:45.093 6464-6464/com.example.morteza.listactivitycursor E/AndroidRuntime: FATAL EXCEPTION: main
        Process: com.example.morteza.listactivitycursor, PID: 6464
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.morteza.listactivitycursor/com.example.morteza.listactivitycursor.MainActivity}: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{afac265 6464:com.example.morteza.listactivitycursor/u0a98} (pid=6464, uid=10098) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
            at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
            at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
            at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
            at android.os.Handler.dispatchMessage(Handler.java:106)
            at android.os.Looper.loop(Looper.java:193)
            at android.app.ActivityThread.main(ActivityThread.java:6669)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
         Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord{afac265 6464:com.example.morteza.listactivitycursor/u0a98} (pid=6464, uid=10098) requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS
            at android.os.Parcel.createException(Parcel.java:1942)
            at android.os.Parcel.readException(Parcel.java:1910)
            at android.os.Parcel.readException(Parcel.java:1860)
            at android.app.IActivityManager$Stub$Proxy.getContentProvider(IActivityManager.java:4181)
            at android.app.ActivityThread.acquireProvider(ActivityThread.java:5970)
            at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2592)
            at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1828)
            at android.content.ContentResolver.query(ContentResolver.java:786)
            at android.content.ContentResolver.query(ContentResolver.java:752)
            at android.content.ContentResolver.query(ContentResolver.java:710)
            at com.example.morteza.listactivitycursor.MainActivity.getContacts(MainActivity.java:35)
            at com.example.morteza.listactivitycursor.MainActivity.onCreate(MainActivity.java:17)
            at android.app.Activity.performCreate(Activity.java:7136)
            at android.app.Activity.performCreate(Activity.java:7127)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
            at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
            at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
            at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
            at android.os.Handler.dispatchMessage(Handler.java:106) 
            at android.os.Looper.loop(Looper.java:193) 
            at android.app.ActivityThread.main(ActivityThread.java:6669) 
            at java.lang.reflect.Method.invoke(Native Method) 
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
         Caused by: android.os.RemoteException: Remote stack trace:
            at com.android.server.am.ActivityManagerService.getContentProviderImpl(ActivityManagerService.java:12185)
            at com.android.server.am.ActivityManagerService.getContentProvider(ActivityManagerService.java:12582)
            at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:357)
            at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3288)
            at android.os.Binder.execTransact(Binder.java:731)
    08-18 17:36:45.112 6464-6464/com.example.morteza.listactivitycursor I/Process: Sending signal. PID: 6464 SIG: 9</p>
  </blockquote>
  
  <p>What is wrong?</p>