Neither user 10102 nor current process has android.permission.READ_PHONE_STATE
Asked Answered
C

4

90

I am trying to call getCallCapablePhoneAccounts() method of android.telecom.TelecomManager class. Though i have added required user-permission, i am getting Security exception.

Here is the line of code where i am getting exception

List<PhoneAccountHandle> list = getTelecomManager().getCallCapablePhoneAccounts();

user permission added in manifest

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

Exception stacktrace Caused by: java.lang.SecurityException: getDefaultOutgoingPhoneAccount: Neither user 10102 nor current process has android.permission.READ_PHONE_STATE. at android.os.Parcel.readException(Parcel.java:1599) at android.os.Parcel.readException(Parcel.java:1552) at com.android.internal.telecom.ITelecomService$Stub$Proxy.getDefaultOutgoingPhoneAccount(ITelecomService.java:615) at android.telecom.TelecomManager.getDefaultOutgoingPhoneAccount(TelecomManager.java:439)

Charter answered 23/9, 2015 at 14:27 Comment(9)
What did you add to your manifest?Portend
Try a clean and rebuild. If not, deleting the permission and re-adding it supposedly fixes things: #12778668Catenary
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> this is been added in manifestCharter
Tried clean, rebuild, but issue still existsCharter
I am also getting the same issue, after I upgraded my emulator target android 6. @Charter were you able to find a solution?Labrador
It seems this is some issue with Android M code.google.com/p/android-developer-preview/issues/…Labrador
@Rusheel, not yet found the solution. These APIs are added in level 23(android M). It seems to be a bug in the frameworkCharter
@Charter You can try to compile your app for api 23 i.e. compile sdk version 23 and target sdk version 23. While on the emulator you can run an older Android like Lollipop (API 21). This should work. I know this is just a workaround to check if your code works fine till a solution for permissions issue is released by android developersLabrador
Finally this is fixed by changing targetSdk level to 4Charter
C
89

On Android >=6.0, We have to request permission runtime.

Step1: add in AndroidManifest.xml file

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

Step2: Request permission.

int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE);

if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_READ_PHONE_STATE);
} else {
    //TODO
}

Step3: Handle callback when you request permission.

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    switch (requestCode) {
        case REQUEST_READ_PHONE_STATE:
            if ((grantResults.length > 0) && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
                //TODO
            }
            break;

        default:
            break;
    }
}

Edit: Read official guide here Requesting Permissions at Run Time

Christiechristin answered 5/8, 2016 at 6:48 Comment(7)
Thank for this. Don't forget, you also need to ensure your activity implements ActivityCompat.OnRequestPermissionsResultCallback.Shirk
the right package is android.Manifest.permission.READ_PHONE_STATEViborg
I got this error on Xiaomi Mi 4i os version:5.0.2 so what can i do?Neckpiece
REQUEST_READ_PHONE_STATE here is an app-defined int constant. The callback method gets the result of the request (comment from documentation).Cauline
I get Cannot resolve symbol REQUEST_READ_PHONE_STATEZygosis
Got it, I forgot this private final int REQUEST_READ_PHONE_STATE=1;Zygosis
BTW, by my experience this specific permission READ_PHONE_STATE is acting somewhat strange. Tried on LG G5 API 26. It needs runtime request to be granted, but on the other hand when requested granted automatically without displaying UI, and also does not appear for the user in the app's runtime permissions.Gisarme
R
54

Are you running Android M? If so, this is because it's not enough to declare permissions in the manifest. For some permissions, you have to explicitly ask user in the runtime: http://developer.android.com/training/permissions/requesting.html

Remanence answered 27/11, 2015 at 7:9 Comment(2)
Wrong answer! I am running Android M, but targeting Android L. In such case it IS enough to declare permissions in the manifest. Correct answer to the question is to declare permission android.Manifest.permission.READ_PHONE_STATE instead of android.permission.READ_PHONE_STATE.Dao
@Dao that is not enough: if you target Android L the permission is automatically granted at installation time, but the user can always disable it from system settings.Antakiya
G
10

I was experiencing this problem on Samsung devices (fine on others). like zyamys suggested in his/her comment, I added the manifest.permission line but in addition to rather than instead of the original line, so:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.Manifest.permission.READ_PHONE_STATE" />

I'm targeting API 22, so don't need to explicitly ask for permissions.

Generalissimo answered 23/5, 2017 at 15:10 Comment(0)
N
0

after I started coding I saw the same issue about my google maps permission. After I read here I understand that same time I asked for permission. I used one bloc to emit location data and should be initialized when open. but the same time I was asking to perm. That means to me while I didn't get the permission I was trying to do something with permission. so I refactor the code first take perm grant from phone and then init all the things with the perm. maybe all kind of "..... neither user have perm.." errors come from this kind of problem.

Nudge answered 28/4, 2023 at 13:31 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Grizzly

© 2022 - 2024 — McMap. All rights reserved.