2

I am developing an Android application in Android 6 and my application in a service needs to get device ID(getDeviceId). I have set android.permission.READ_PHONE_STATE in the manifest file, but at run time I got this error:

neither user 10632 nor current process has android.permission.READ_PHONE_STATE. java.lang.SecurityException:getDeviceId need android.permission.Read_Phone_state

I install my apk file using adb install myapk.apk and I suppose that all of application's required permissions are granted at install time.

Stateless
  • 293
  • 2
  • 4
  • 18
  • https://developer.android.com/training/permissions/requesting.html – X3Btel May 16 '17 at 12:26
  • 2
    Possible duplicate of [How to ask for user permissions in Android 6](http://stackoverflow.com/questions/35091327/how-to-ask-for-user-permissions-in-android-6) – X3Btel May 16 '17 at 12:27
  • Possible duplicate of [Neither user 10102 nor current process has android.permission.READ\_PHONE\_STATE](https://stackoverflow.com/questions/32742327/neither-user-10102-nor-current-process-has-android-permission-read-phone-state) – Nick Cardoso Jul 24 '18 at 14:14

2 Answers2

4

You also need to request permission at run time.

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

If the app has the permission, the method returns PackageManager.PERMISSION_GRANTED, and the app can proceed with the operation. If the app does not have the permission, the method returns PERMISSION_DENIED, and the app has to explicitly ask the user for permission.

If you dont get it , you should request it

ActivityCompat.requestPermissions(thisActivity,
                new String[]{Manifest.permission.READ_PHONE_STATE},
                MY_PERMISSIONS_REQUEST_READ_PHONE_STATE);
Dishonered
  • 8,449
  • 9
  • 37
  • 50
1

You need to ask for permissions at runtime in android 6+. Visit android developer page to learn how to ask for permission for android M and above visit : https://developer.android.com/training/permissions/requesting.html

Pro Mode
  • 1,453
  • 17
  • 30