Android Does not show permission request dialog for READ_CONTACT WRITE_CONTACTS










0














I have followed the android guidelines for asking for permissions for Android Devices running VERSION.M and above namely (runtime-permissions), but the permission request dialogue is not shown, instead, the permission is automatically denied.



I am requesting users for READ/WRITE CONTACTS permission as well as other permissions as indicated by my manifest below.



The app requests for other permissions, such as access files, phone, SMS but does not request for read contacts permission.



Here is my manifest file



<uses-permission
android:name="android.permission.AUTHENTICATE_ACCOUNTS"
tools:remove="android:maxSdkVersion"/>

<uses-permission
android:name="android.permission.GET_ACCOUNTS"
tools:remove="android:maxSdkVersion"/>

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECEIVE_MMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.WRITE_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="Manifest.permission.READ_CONTACTS"
tools:remove="android:maxSdkVersion"/>
<uses-permission android:name="Manifest.permission.WRITE_CONTACTS"
tools:remove="android:maxSdkVersion"/>
<uses-permission android:name="Manifest.permission.CONTACTS"/>

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.READ_CALL_STATE" />

<!-- For sending/receiving events -->
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
<uses-permission android:name="android.permission.RAISED_THREAD_PRIORITY" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

<!-- Normal -->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

<!-- So we can add a TextSecure 'Account' -->
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />

<!-- For conversation 'shortcuts' on the desktop -->
<uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

<!-- For fixing MMS -->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

<uses-feature
android:name="android.hardware.microphone"
android:required="false" />
<uses-feature
android:name="android.hardware.wifi"
android:required="false" />
<uses-feature
android:name="android.hardware.portrait"
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
<uses-permission android:name="com.google.android.providers.gsf.permmission.READ_GSERVICES" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.BROADCAST_WAP_PUSH"
tools:ignore="ProtectedPermissions" />

<uses-feature
android:name="android.hardware.camera"
android:required="true" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


Here is my explicit read contact permission request block



private void loadDeviceContactsOnAndroid_M() 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
if (checkSelfPermission(Manifest.permission_group.CONTACTS) == PackageManager.PERMISSION_GRANTED)
Log.e(getClass().getSimpleName(), "Read contacts permission granted");
loadAndDisplayConfiguredRecipients();
else
Log.e(getClass().getSimpleName(), "Read contacts permission Not granted");

if (shouldShowRequestPermissionRationale(Manifest.permission_group.CONTACTS))
Toast.makeText(getApplicationContext(), "mPHR messaging feature requires your contacts", Toast.LENGTH_LONG).show();


ActivityCompat.requestPermissions(this,new StringManifest.permission_group.CONTACTS, 101);

else
Toast.makeText(getApplicationContext(), "Android Version is " + Build.VERSION.SDK_INT, Toast.LENGTH_LONG).show();



Here is my onRequestPermissionResult callback method



@Override
public void onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
if (requestCode == 101)
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
Toast.makeText(this, "Hurray permission granted ", Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "Until you grant the permission, we cannot display the names", Toast.LENGTH_SHORT).show();





Here is my contacts loader method block



Cursor cursor = contactController.querySystemContacts("");
if (cursor.moveToFirst())
do
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
messageRecipients.add(name);
while (cursor.moveToNext());


cursor.close();


The application does not request the user for the contacts permission and when I bypass this and try to go ahead and access the contact on device I get the permission denied security error;



java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord13c53b7 14017:my/app/package/name/u0a183 

(pid=159017, uid=10183)

requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS


I am running my tests on Android 8 physical devices.



When I use the same code for say, ACCESS_COARSE_LOCATION_PERMISSION it works perfectly but fails when I use READ_CONTACT or WRITE_CONTACTS










share|improve this question




























    0














    I have followed the android guidelines for asking for permissions for Android Devices running VERSION.M and above namely (runtime-permissions), but the permission request dialogue is not shown, instead, the permission is automatically denied.



    I am requesting users for READ/WRITE CONTACTS permission as well as other permissions as indicated by my manifest below.



    The app requests for other permissions, such as access files, phone, SMS but does not request for read contacts permission.



    Here is my manifest file



    <uses-permission
    android:name="android.permission.AUTHENTICATE_ACCOUNTS"
    tools:remove="android:maxSdkVersion"/>

    <uses-permission
    android:name="android.permission.GET_ACCOUNTS"
    tools:remove="android:maxSdkVersion"/>

    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_MMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.SEND_SMS" />
    <uses-permission android:name="android.permission.WRITE_SMS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="Manifest.permission.READ_CONTACTS"
    tools:remove="android:maxSdkVersion"/>
    <uses-permission android:name="Manifest.permission.WRITE_CONTACTS"
    tools:remove="android:maxSdkVersion"/>
    <uses-permission android:name="Manifest.permission.CONTACTS"/>

    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-permission android:name="android.permission.READ_CALL_STATE" />

    <!-- For sending/receiving events -->
    <uses-permission android:name="android.permission.WRITE_CALENDAR" />
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
    <uses-permission android:name="android.permission.RAISED_THREAD_PRIORITY" />
    <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

    <!-- Normal -->
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

    <!-- So we can add a TextSecure 'Account' -->
    <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />

    <!-- For conversation 'shortcuts' on the desktop -->
    <uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

    <!-- For fixing MMS -->
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

    <uses-feature
    android:name="android.hardware.microphone"
    android:required="false" />
    <uses-feature
    android:name="android.hardware.wifi"
    android:required="false" />
    <uses-feature
    android:name="android.hardware.portrait"
    android:required="false" />
    <uses-feature
    android:name="android.hardware.touchscreen"
    android:required="false" />

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
    <uses-permission android:name="com.google.android.providers.gsf.permmission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission
    android:name="android.permission.BROADCAST_WAP_PUSH"
    tools:ignore="ProtectedPermissions" />

    <uses-feature
    android:name="android.hardware.camera"
    android:required="true" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


    Here is my explicit read contact permission request block



    private void loadDeviceContactsOnAndroid_M() 

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
    if (checkSelfPermission(Manifest.permission_group.CONTACTS) == PackageManager.PERMISSION_GRANTED)
    Log.e(getClass().getSimpleName(), "Read contacts permission granted");
    loadAndDisplayConfiguredRecipients();
    else
    Log.e(getClass().getSimpleName(), "Read contacts permission Not granted");

    if (shouldShowRequestPermissionRationale(Manifest.permission_group.CONTACTS))
    Toast.makeText(getApplicationContext(), "mPHR messaging feature requires your contacts", Toast.LENGTH_LONG).show();


    ActivityCompat.requestPermissions(this,new StringManifest.permission_group.CONTACTS, 101);

    else
    Toast.makeText(getApplicationContext(), "Android Version is " + Build.VERSION.SDK_INT, Toast.LENGTH_LONG).show();



    Here is my onRequestPermissionResult callback method



    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
    if (requestCode == 101)
    if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
    Toast.makeText(this, "Hurray permission granted ", Toast.LENGTH_SHORT).show();
    else
    Toast.makeText(this, "Until you grant the permission, we cannot display the names", Toast.LENGTH_SHORT).show();





    Here is my contacts loader method block



    Cursor cursor = contactController.querySystemContacts("");
    if (cursor.moveToFirst())
    do
    String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
    messageRecipients.add(name);
    while (cursor.moveToNext());


    cursor.close();


    The application does not request the user for the contacts permission and when I bypass this and try to go ahead and access the contact on device I get the permission denied security error;



    java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord13c53b7 14017:my/app/package/name/u0a183 

    (pid=159017, uid=10183)

    requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS


    I am running my tests on Android 8 physical devices.



    When I use the same code for say, ACCESS_COARSE_LOCATION_PERMISSION it works perfectly but fails when I use READ_CONTACT or WRITE_CONTACTS










    share|improve this question


























      0












      0








      0







      I have followed the android guidelines for asking for permissions for Android Devices running VERSION.M and above namely (runtime-permissions), but the permission request dialogue is not shown, instead, the permission is automatically denied.



      I am requesting users for READ/WRITE CONTACTS permission as well as other permissions as indicated by my manifest below.



      The app requests for other permissions, such as access files, phone, SMS but does not request for read contacts permission.



      Here is my manifest file



      <uses-permission
      android:name="android.permission.AUTHENTICATE_ACCOUNTS"
      tools:remove="android:maxSdkVersion"/>

      <uses-permission
      android:name="android.permission.GET_ACCOUNTS"
      tools:remove="android:maxSdkVersion"/>

      <uses-permission android:name="android.permission.RECEIVE_SMS" />
      <uses-permission android:name="android.permission.RECEIVE_MMS" />
      <uses-permission android:name="android.permission.READ_SMS" />
      <uses-permission android:name="android.permission.SEND_SMS" />
      <uses-permission android:name="android.permission.WRITE_SMS" />
      <uses-permission android:name="android.permission.READ_PHONE_STATE" />
      <uses-permission android:name="Manifest.permission.READ_CONTACTS"
      tools:remove="android:maxSdkVersion"/>
      <uses-permission android:name="Manifest.permission.WRITE_CONTACTS"
      tools:remove="android:maxSdkVersion"/>
      <uses-permission android:name="Manifest.permission.CONTACTS"/>

      <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
      <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
      <uses-permission android:name="android.permission.READ_CALL_STATE" />

      <!-- For sending/receiving events -->
      <uses-permission android:name="android.permission.WRITE_CALENDAR" />
      <uses-permission android:name="android.permission.READ_CALENDAR" />
      <uses-permission android:name="android.permission.CALL_PHONE" />
      <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
      <uses-permission android:name="android.permission.RAISED_THREAD_PRIORITY" />
      <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

      <!-- Normal -->
      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
      <uses-permission android:name="android.permission.VIBRATE" />
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
      <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

      <!-- So we can add a TextSecure 'Account' -->
      <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
      <uses-permission android:name="android.permission.USE_CREDENTIALS" />

      <!-- For conversation 'shortcuts' on the desktop -->
      <uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
      <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

      <!-- For fixing MMS -->
      <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
      <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

      <uses-feature
      android:name="android.hardware.microphone"
      android:required="false" />
      <uses-feature
      android:name="android.hardware.wifi"
      android:required="false" />
      <uses-feature
      android:name="android.hardware.portrait"
      android:required="false" />
      <uses-feature
      android:name="android.hardware.touchscreen"
      android:required="false" />

      <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
      <uses-permission android:name="android.permission.WAKE_LOCK" />
      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
      <uses-permission android:name="com.google.android.providers.gsf.permmission.READ_GSERVICES" />
      <uses-permission android:name="android.permission.RECORD_AUDIO" />
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
      <uses-permission
      android:name="android.permission.BROADCAST_WAP_PUSH"
      tools:ignore="ProtectedPermissions" />

      <uses-feature
      android:name="android.hardware.camera"
      android:required="true" />
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


      Here is my explicit read contact permission request block



      private void loadDeviceContactsOnAndroid_M() 

      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
      if (checkSelfPermission(Manifest.permission_group.CONTACTS) == PackageManager.PERMISSION_GRANTED)
      Log.e(getClass().getSimpleName(), "Read contacts permission granted");
      loadAndDisplayConfiguredRecipients();
      else
      Log.e(getClass().getSimpleName(), "Read contacts permission Not granted");

      if (shouldShowRequestPermissionRationale(Manifest.permission_group.CONTACTS))
      Toast.makeText(getApplicationContext(), "mPHR messaging feature requires your contacts", Toast.LENGTH_LONG).show();


      ActivityCompat.requestPermissions(this,new StringManifest.permission_group.CONTACTS, 101);

      else
      Toast.makeText(getApplicationContext(), "Android Version is " + Build.VERSION.SDK_INT, Toast.LENGTH_LONG).show();



      Here is my onRequestPermissionResult callback method



      @Override
      public void onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
      if (requestCode == 101)
      if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
      Toast.makeText(this, "Hurray permission granted ", Toast.LENGTH_SHORT).show();
      else
      Toast.makeText(this, "Until you grant the permission, we cannot display the names", Toast.LENGTH_SHORT).show();





      Here is my contacts loader method block



      Cursor cursor = contactController.querySystemContacts("");
      if (cursor.moveToFirst())
      do
      String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
      messageRecipients.add(name);
      while (cursor.moveToNext());


      cursor.close();


      The application does not request the user for the contacts permission and when I bypass this and try to go ahead and access the contact on device I get the permission denied security error;



      java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord13c53b7 14017:my/app/package/name/u0a183 

      (pid=159017, uid=10183)

      requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS


      I am running my tests on Android 8 physical devices.



      When I use the same code for say, ACCESS_COARSE_LOCATION_PERMISSION it works perfectly but fails when I use READ_CONTACT or WRITE_CONTACTS










      share|improve this question















      I have followed the android guidelines for asking for permissions for Android Devices running VERSION.M and above namely (runtime-permissions), but the permission request dialogue is not shown, instead, the permission is automatically denied.



      I am requesting users for READ/WRITE CONTACTS permission as well as other permissions as indicated by my manifest below.



      The app requests for other permissions, such as access files, phone, SMS but does not request for read contacts permission.



      Here is my manifest file



      <uses-permission
      android:name="android.permission.AUTHENTICATE_ACCOUNTS"
      tools:remove="android:maxSdkVersion"/>

      <uses-permission
      android:name="android.permission.GET_ACCOUNTS"
      tools:remove="android:maxSdkVersion"/>

      <uses-permission android:name="android.permission.RECEIVE_SMS" />
      <uses-permission android:name="android.permission.RECEIVE_MMS" />
      <uses-permission android:name="android.permission.READ_SMS" />
      <uses-permission android:name="android.permission.SEND_SMS" />
      <uses-permission android:name="android.permission.WRITE_SMS" />
      <uses-permission android:name="android.permission.READ_PHONE_STATE" />
      <uses-permission android:name="Manifest.permission.READ_CONTACTS"
      tools:remove="android:maxSdkVersion"/>
      <uses-permission android:name="Manifest.permission.WRITE_CONTACTS"
      tools:remove="android:maxSdkVersion"/>
      <uses-permission android:name="Manifest.permission.CONTACTS"/>

      <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
      <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
      <uses-permission android:name="android.permission.READ_CALL_STATE" />

      <!-- For sending/receiving events -->
      <uses-permission android:name="android.permission.WRITE_CALENDAR" />
      <uses-permission android:name="android.permission.READ_CALENDAR" />
      <uses-permission android:name="android.permission.CALL_PHONE" />
      <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
      <uses-permission android:name="android.permission.RAISED_THREAD_PRIORITY" />
      <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

      <!-- Normal -->
      <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
      <uses-permission android:name="android.permission.VIBRATE" />
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
      <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />

      <!-- So we can add a TextSecure 'Account' -->
      <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
      <uses-permission android:name="android.permission.USE_CREDENTIALS" />

      <!-- For conversation 'shortcuts' on the desktop -->
      <uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
      <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

      <!-- For fixing MMS -->
      <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
      <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

      <uses-feature
      android:name="android.hardware.microphone"
      android:required="false" />
      <uses-feature
      android:name="android.hardware.wifi"
      android:required="false" />
      <uses-feature
      android:name="android.hardware.portrait"
      android:required="false" />
      <uses-feature
      android:name="android.hardware.touchscreen"
      android:required="false" />

      <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
      <uses-permission android:name="android.permission.WAKE_LOCK" />
      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
      <uses-permission android:name="com.google.android.providers.gsf.permmission.READ_GSERVICES" />
      <uses-permission android:name="android.permission.RECORD_AUDIO" />
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
      <uses-permission
      android:name="android.permission.BROADCAST_WAP_PUSH"
      tools:ignore="ProtectedPermissions" />

      <uses-feature
      android:name="android.hardware.camera"
      android:required="true" />
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


      Here is my explicit read contact permission request block



      private void loadDeviceContactsOnAndroid_M() 

      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
      if (checkSelfPermission(Manifest.permission_group.CONTACTS) == PackageManager.PERMISSION_GRANTED)
      Log.e(getClass().getSimpleName(), "Read contacts permission granted");
      loadAndDisplayConfiguredRecipients();
      else
      Log.e(getClass().getSimpleName(), "Read contacts permission Not granted");

      if (shouldShowRequestPermissionRationale(Manifest.permission_group.CONTACTS))
      Toast.makeText(getApplicationContext(), "mPHR messaging feature requires your contacts", Toast.LENGTH_LONG).show();


      ActivityCompat.requestPermissions(this,new StringManifest.permission_group.CONTACTS, 101);

      else
      Toast.makeText(getApplicationContext(), "Android Version is " + Build.VERSION.SDK_INT, Toast.LENGTH_LONG).show();



      Here is my onRequestPermissionResult callback method



      @Override
      public void onRequestPermissionsResult(int requestCode, String permissions, int grantResults)
      if (requestCode == 101)
      if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
      Toast.makeText(this, "Hurray permission granted ", Toast.LENGTH_SHORT).show();
      else
      Toast.makeText(this, "Until you grant the permission, we cannot display the names", Toast.LENGTH_SHORT).show();





      Here is my contacts loader method block



      Cursor cursor = contactController.querySystemContacts("");
      if (cursor.moveToFirst())
      do
      String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
      messageRecipients.add(name);
      while (cursor.moveToNext());


      cursor.close();


      The application does not request the user for the contacts permission and when I bypass this and try to go ahead and access the contact on device I get the permission denied security error;



      java.lang.SecurityException: Permission Denial: opening provider com.android.providers.contacts.ContactsProvider2 from ProcessRecord13c53b7 14017:my/app/package/name/u0a183 

      (pid=159017, uid=10183)

      requires android.permission.READ_CONTACTS or android.permission.WRITE_CONTACTS


      I am running my tests on Android 8 physical devices.



      When I use the same code for say, ACCESS_COARSE_LOCATION_PERMISSION it works perfectly but fails when I use READ_CONTACT or WRITE_CONTACTS







      android security android-permissions android-6.0-marshmallow






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 8:30







      samuel owino

















      asked Nov 13 '18 at 8:21









      samuel owinosamuel owino

      307414




      307414






















          2 Answers
          2






          active

          oldest

          votes


















          1














          I have not tried your code, but please do not use checkSelfPermission directly. Use ContextCompat.checkSelfPermission method instead as google recommends.



          if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.WRITE_CALENDAR)
          != PackageManager.PERMISSION_GRANTED)
          // Permission is not granted



          https://developer.android.com/training/permissions/requesting#java



          When I add code for permission check, I was doing permission check individually which means that I was checking permission one by one rather than checking permission group. So I will try it later. But for now, please try with ContextCompat method.



          EDIT:



          Please do not request by permission group. The permission request model in Android M is for individual permission only.
          So here is what you can do.



          private void checkPermission() 
          if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED



          EDIT:



          Please do not use the followings in your manifest.



          <uses-permission android:name="Manifest.permission.READ_CONTACTS"
          tools:remove="android:maxSdkVersion"/>
          <uses-permission android:name="Manifest.permission.WRITE_CONTACTS"
          tools:remove="android:maxSdkVersion"/>
          <uses-permission android:name="Manifest.permission.CONTACTS"/>


          You can just replace them with the followings.



          <uses-permission android:name="android.permission.READ_CONTACTS" />
          <uses-permission android:name="android.permission.WRITE_CONTACTS" />





          share|improve this answer






















          • Thanks, @Kenny ill make the adjustment, let me know what you find out
            – samuel owino
            Nov 13 '18 at 8:54










          • @samuelowino Okay, I edited my answer. So you can check it out.
            – Kenny
            Nov 13 '18 at 9:05










          • Does it work on your end?
            – samuel owino
            Nov 13 '18 at 9:05










          • Yes, it works for me
            – Kenny
            Nov 13 '18 at 9:06










          • developer.android.com/guide/topics/permissions/overview
            – Kenny
            Nov 13 '18 at 9:09


















          1














          You can either request for permission on the start of the application or runtime when you need to use it.
          Try this library (https://github.com/nabinbhandari/Android-Permissions). It gives you lots of options like when the user deny or grant the permission and also you can ask for multiple permissions.



          Example



          Single Permission



          Permissions.check(this/*context*/, Manifest.permission.READ_CONTACTS, null, new PermissionHandler() 
          @Override
          public void onGranted()
          // do your task.
          );


          multiple permission



          String permissions = Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE;Permissions.check(this/*context*/, permissions, null/*rationale*/, null/*options*/, new PermissionHandler() 
          @Override
          public void onGranted()
          // do your task.
          );


          NOTE
          Using libraries is not a good practice unless they are well maintained






          share|improve this answer




















          • This is really helpful, though I agree with you using a library for a core-security functionality such as device permissions, might not be the best way to approach this. None the less it works!!!. Thanks :)
            – samuel owino
            Nov 15 '18 at 8:51











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276666%2fandroid-does-not-show-permission-request-dialog-for-read-contact-write-contacts%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          I have not tried your code, but please do not use checkSelfPermission directly. Use ContextCompat.checkSelfPermission method instead as google recommends.



          if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.WRITE_CALENDAR)
          != PackageManager.PERMISSION_GRANTED)
          // Permission is not granted



          https://developer.android.com/training/permissions/requesting#java



          When I add code for permission check, I was doing permission check individually which means that I was checking permission one by one rather than checking permission group. So I will try it later. But for now, please try with ContextCompat method.



          EDIT:



          Please do not request by permission group. The permission request model in Android M is for individual permission only.
          So here is what you can do.



          private void checkPermission() 
          if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED



          EDIT:



          Please do not use the followings in your manifest.



          <uses-permission android:name="Manifest.permission.READ_CONTACTS"
          tools:remove="android:maxSdkVersion"/>
          <uses-permission android:name="Manifest.permission.WRITE_CONTACTS"
          tools:remove="android:maxSdkVersion"/>
          <uses-permission android:name="Manifest.permission.CONTACTS"/>


          You can just replace them with the followings.



          <uses-permission android:name="android.permission.READ_CONTACTS" />
          <uses-permission android:name="android.permission.WRITE_CONTACTS" />





          share|improve this answer






















          • Thanks, @Kenny ill make the adjustment, let me know what you find out
            – samuel owino
            Nov 13 '18 at 8:54










          • @samuelowino Okay, I edited my answer. So you can check it out.
            – Kenny
            Nov 13 '18 at 9:05










          • Does it work on your end?
            – samuel owino
            Nov 13 '18 at 9:05










          • Yes, it works for me
            – Kenny
            Nov 13 '18 at 9:06










          • developer.android.com/guide/topics/permissions/overview
            – Kenny
            Nov 13 '18 at 9:09















          1














          I have not tried your code, but please do not use checkSelfPermission directly. Use ContextCompat.checkSelfPermission method instead as google recommends.



          if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.WRITE_CALENDAR)
          != PackageManager.PERMISSION_GRANTED)
          // Permission is not granted



          https://developer.android.com/training/permissions/requesting#java



          When I add code for permission check, I was doing permission check individually which means that I was checking permission one by one rather than checking permission group. So I will try it later. But for now, please try with ContextCompat method.



          EDIT:



          Please do not request by permission group. The permission request model in Android M is for individual permission only.
          So here is what you can do.



          private void checkPermission() 
          if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED



          EDIT:



          Please do not use the followings in your manifest.



          <uses-permission android:name="Manifest.permission.READ_CONTACTS"
          tools:remove="android:maxSdkVersion"/>
          <uses-permission android:name="Manifest.permission.WRITE_CONTACTS"
          tools:remove="android:maxSdkVersion"/>
          <uses-permission android:name="Manifest.permission.CONTACTS"/>


          You can just replace them with the followings.



          <uses-permission android:name="android.permission.READ_CONTACTS" />
          <uses-permission android:name="android.permission.WRITE_CONTACTS" />





          share|improve this answer






















          • Thanks, @Kenny ill make the adjustment, let me know what you find out
            – samuel owino
            Nov 13 '18 at 8:54










          • @samuelowino Okay, I edited my answer. So you can check it out.
            – Kenny
            Nov 13 '18 at 9:05










          • Does it work on your end?
            – samuel owino
            Nov 13 '18 at 9:05










          • Yes, it works for me
            – Kenny
            Nov 13 '18 at 9:06










          • developer.android.com/guide/topics/permissions/overview
            – Kenny
            Nov 13 '18 at 9:09













          1












          1








          1






          I have not tried your code, but please do not use checkSelfPermission directly. Use ContextCompat.checkSelfPermission method instead as google recommends.



          if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.WRITE_CALENDAR)
          != PackageManager.PERMISSION_GRANTED)
          // Permission is not granted



          https://developer.android.com/training/permissions/requesting#java



          When I add code for permission check, I was doing permission check individually which means that I was checking permission one by one rather than checking permission group. So I will try it later. But for now, please try with ContextCompat method.



          EDIT:



          Please do not request by permission group. The permission request model in Android M is for individual permission only.
          So here is what you can do.



          private void checkPermission() 
          if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED



          EDIT:



          Please do not use the followings in your manifest.



          <uses-permission android:name="Manifest.permission.READ_CONTACTS"
          tools:remove="android:maxSdkVersion"/>
          <uses-permission android:name="Manifest.permission.WRITE_CONTACTS"
          tools:remove="android:maxSdkVersion"/>
          <uses-permission android:name="Manifest.permission.CONTACTS"/>


          You can just replace them with the followings.



          <uses-permission android:name="android.permission.READ_CONTACTS" />
          <uses-permission android:name="android.permission.WRITE_CONTACTS" />





          share|improve this answer














          I have not tried your code, but please do not use checkSelfPermission directly. Use ContextCompat.checkSelfPermission method instead as google recommends.



          if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.WRITE_CALENDAR)
          != PackageManager.PERMISSION_GRANTED)
          // Permission is not granted



          https://developer.android.com/training/permissions/requesting#java



          When I add code for permission check, I was doing permission check individually which means that I was checking permission one by one rather than checking permission group. So I will try it later. But for now, please try with ContextCompat method.



          EDIT:



          Please do not request by permission group. The permission request model in Android M is for individual permission only.
          So here is what you can do.



          private void checkPermission() 
          if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED



          EDIT:



          Please do not use the followings in your manifest.



          <uses-permission android:name="Manifest.permission.READ_CONTACTS"
          tools:remove="android:maxSdkVersion"/>
          <uses-permission android:name="Manifest.permission.WRITE_CONTACTS"
          tools:remove="android:maxSdkVersion"/>
          <uses-permission android:name="Manifest.permission.CONTACTS"/>


          You can just replace them with the followings.



          <uses-permission android:name="android.permission.READ_CONTACTS" />
          <uses-permission android:name="android.permission.WRITE_CONTACTS" />






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 13 '18 at 9:32

























          answered Nov 13 '18 at 8:42









          KennyKenny

          1218




          1218











          • Thanks, @Kenny ill make the adjustment, let me know what you find out
            – samuel owino
            Nov 13 '18 at 8:54










          • @samuelowino Okay, I edited my answer. So you can check it out.
            – Kenny
            Nov 13 '18 at 9:05










          • Does it work on your end?
            – samuel owino
            Nov 13 '18 at 9:05










          • Yes, it works for me
            – Kenny
            Nov 13 '18 at 9:06










          • developer.android.com/guide/topics/permissions/overview
            – Kenny
            Nov 13 '18 at 9:09
















          • Thanks, @Kenny ill make the adjustment, let me know what you find out
            – samuel owino
            Nov 13 '18 at 8:54










          • @samuelowino Okay, I edited my answer. So you can check it out.
            – Kenny
            Nov 13 '18 at 9:05










          • Does it work on your end?
            – samuel owino
            Nov 13 '18 at 9:05










          • Yes, it works for me
            – Kenny
            Nov 13 '18 at 9:06










          • developer.android.com/guide/topics/permissions/overview
            – Kenny
            Nov 13 '18 at 9:09















          Thanks, @Kenny ill make the adjustment, let me know what you find out
          – samuel owino
          Nov 13 '18 at 8:54




          Thanks, @Kenny ill make the adjustment, let me know what you find out
          – samuel owino
          Nov 13 '18 at 8:54












          @samuelowino Okay, I edited my answer. So you can check it out.
          – Kenny
          Nov 13 '18 at 9:05




          @samuelowino Okay, I edited my answer. So you can check it out.
          – Kenny
          Nov 13 '18 at 9:05












          Does it work on your end?
          – samuel owino
          Nov 13 '18 at 9:05




          Does it work on your end?
          – samuel owino
          Nov 13 '18 at 9:05












          Yes, it works for me
          – Kenny
          Nov 13 '18 at 9:06




          Yes, it works for me
          – Kenny
          Nov 13 '18 at 9:06












          developer.android.com/guide/topics/permissions/overview
          – Kenny
          Nov 13 '18 at 9:09




          developer.android.com/guide/topics/permissions/overview
          – Kenny
          Nov 13 '18 at 9:09













          1














          You can either request for permission on the start of the application or runtime when you need to use it.
          Try this library (https://github.com/nabinbhandari/Android-Permissions). It gives you lots of options like when the user deny or grant the permission and also you can ask for multiple permissions.



          Example



          Single Permission



          Permissions.check(this/*context*/, Manifest.permission.READ_CONTACTS, null, new PermissionHandler() 
          @Override
          public void onGranted()
          // do your task.
          );


          multiple permission



          String permissions = Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE;Permissions.check(this/*context*/, permissions, null/*rationale*/, null/*options*/, new PermissionHandler() 
          @Override
          public void onGranted()
          // do your task.
          );


          NOTE
          Using libraries is not a good practice unless they are well maintained






          share|improve this answer




















          • This is really helpful, though I agree with you using a library for a core-security functionality such as device permissions, might not be the best way to approach this. None the less it works!!!. Thanks :)
            – samuel owino
            Nov 15 '18 at 8:51
















          1














          You can either request for permission on the start of the application or runtime when you need to use it.
          Try this library (https://github.com/nabinbhandari/Android-Permissions). It gives you lots of options like when the user deny or grant the permission and also you can ask for multiple permissions.



          Example



          Single Permission



          Permissions.check(this/*context*/, Manifest.permission.READ_CONTACTS, null, new PermissionHandler() 
          @Override
          public void onGranted()
          // do your task.
          );


          multiple permission



          String permissions = Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE;Permissions.check(this/*context*/, permissions, null/*rationale*/, null/*options*/, new PermissionHandler() 
          @Override
          public void onGranted()
          // do your task.
          );


          NOTE
          Using libraries is not a good practice unless they are well maintained






          share|improve this answer




















          • This is really helpful, though I agree with you using a library for a core-security functionality such as device permissions, might not be the best way to approach this. None the less it works!!!. Thanks :)
            – samuel owino
            Nov 15 '18 at 8:51














          1












          1








          1






          You can either request for permission on the start of the application or runtime when you need to use it.
          Try this library (https://github.com/nabinbhandari/Android-Permissions). It gives you lots of options like when the user deny or grant the permission and also you can ask for multiple permissions.



          Example



          Single Permission



          Permissions.check(this/*context*/, Manifest.permission.READ_CONTACTS, null, new PermissionHandler() 
          @Override
          public void onGranted()
          // do your task.
          );


          multiple permission



          String permissions = Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE;Permissions.check(this/*context*/, permissions, null/*rationale*/, null/*options*/, new PermissionHandler() 
          @Override
          public void onGranted()
          // do your task.
          );


          NOTE
          Using libraries is not a good practice unless they are well maintained






          share|improve this answer












          You can either request for permission on the start of the application or runtime when you need to use it.
          Try this library (https://github.com/nabinbhandari/Android-Permissions). It gives you lots of options like when the user deny or grant the permission and also you can ask for multiple permissions.



          Example



          Single Permission



          Permissions.check(this/*context*/, Manifest.permission.READ_CONTACTS, null, new PermissionHandler() 
          @Override
          public void onGranted()
          // do your task.
          );


          multiple permission



          String permissions = Manifest.permission.READ_CONTACTS, Manifest.permission.WRITE_EXTERNAL_STORAGE;Permissions.check(this/*context*/, permissions, null/*rationale*/, null/*options*/, new PermissionHandler() 
          @Override
          public void onGranted()
          // do your task.
          );


          NOTE
          Using libraries is not a good practice unless they are well maintained







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 14 '18 at 9:25









          corneliouz Bettcorneliouz Bett

          113




          113











          • This is really helpful, though I agree with you using a library for a core-security functionality such as device permissions, might not be the best way to approach this. None the less it works!!!. Thanks :)
            – samuel owino
            Nov 15 '18 at 8:51

















          • This is really helpful, though I agree with you using a library for a core-security functionality such as device permissions, might not be the best way to approach this. None the less it works!!!. Thanks :)
            – samuel owino
            Nov 15 '18 at 8:51
















          This is really helpful, though I agree with you using a library for a core-security functionality such as device permissions, might not be the best way to approach this. None the less it works!!!. Thanks :)
          – samuel owino
          Nov 15 '18 at 8:51





          This is really helpful, though I agree with you using a library for a core-security functionality such as device permissions, might not be the best way to approach this. None the less it works!!!. Thanks :)
          – samuel owino
          Nov 15 '18 at 8:51


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53276666%2fandroid-does-not-show-permission-request-dialog-for-read-contact-write-contacts%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          政党

          天津地下鉄3号線