1

I have an Android application which need the permissions: READ_PHONE_STATE & CALL_PHONE. I've declared these permissions in the Manifest and it works fine for SDK < 23.

Now in Android 6 (SDK 23) I'm asking the user to grant this permission in runtime. In the documentation, they say the if the user has granted one of the above permission, he actually granted all the permissions that are found in the same group permissions, in this case all the permission that are related to the phone group permissions.

But I'm facing with a problem, when I'm using telephony manager to get the deviceid, I'm getting a security exceptions that says that I don't have any access, even though the user has granted the "call phone" permission, why is that?

Update: I'm requesting multiple permissions

In Manifest.xml

<uses-permission android:name="android.permission.CALL_PHONE">
<uses-permission android:name="android.permission.READ_PHONE_STATE">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE">

In Activity:

ActivityCompat.requestPermissions(this,new String[] 
{                                  
  Manifest.permission.CALL_PHONE,
  Manifest.permission.READ_EXTERNAL_STORAGE
},
permissionRequestcode);
eliorsh
  • 195
  • 1
  • 5
  • 20
  • Please provide a [mcve], demonstrating how you are requesting the permissions. In particular, you need to request both permissions, even if the user will only wind up seeing the confirmation dialog once. – CommonsWare May 25 '16 at 19:36
  • @CommonsWare thanks for your reply, please see my update – eliorsh May 25 '16 at 20:26
  • That looks like that should be OK, assuming that you are waiting on using those permissions until after you have received confirmation that you have them. – CommonsWare May 25 '16 at 20:44
  • Yes, I'm asking these permission on the first launch, but from some reason, when I'm trying to get the device id , using telephonyManager.getDeviceId(), It gives my a securityException says "java.lang.SecurityException: getDeviceId: Neither user 11223 nor current process has android.permission.READ_PHONE_STATE" , even though the permissions were granted! – eliorsh May 25 '16 at 21:03
  • Is there anything unusual about your app structure (e.g., multiple processes)? What is your `targetSdkVersion`? Are you sure that you have your permissions in the correct spot in the manifest (see [this blog post](https://commonsware.com/blog/2015/08/31/hey-where-did-my-permission-go.html))? – CommonsWare May 25 '16 at 21:10
  • I have a service but it shouldn't impact on this problem. the target is 23 and i can't downgrade it to 22, the permissions are located above the application tag – eliorsh May 26 '16 at 06:29
  • Try this it may be work http://stackoverflow.com/a/41221852/5488468 – Bipin Bharti Jan 03 '17 at 10:49

0 Answers0