2

This problem only occurs on API level 23 I tested my code with API 16 and API 22 with no problems.

I use in AndroidManifest:

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

In my code I do:

TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String deviceID = tm.getDeviceId();

When running this code on API23 I get the following error:

10-12 16:31:54.183 3428-3456/? E/AndroidRuntime: java.lang.SecurityException: getDeviceId: Neither user 10058 nor current process has android.permission.READ_PHONE_STATE.
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at android.os.Parcel.readException(Parcel.java:1599)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at android.os.Parcel.readException(Parcel.java:1552)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at com.android.internal.telephony.ITelephony$Stub$Proxy.getDeviceId(ITelephony.java:4175)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at android.telephony.TelephonyManager.getDeviceId(TelephonyManager.java:706)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at de.test.plugins.UniqueDeviceIdAdapterImpl.getUUID(UniqueDeviceIdAdapterImpl.java:29)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at test.core.plugins.uniqueDeviceId.UniqueDeviceIdImpl.getUUID(UniqueDeviceIdImpl.java:16)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at test.core.bootstrap.AppStarter.setDeviceInfo(AppStarter.java:136)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at test.core.bootstrap.AppStarter.<init>(AppStarter.java:103)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at test.core.bootstrap.AppStarter.<init>(AppStarter.java:63)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at test.core.bootstrap.AppStarter$Builder.build(AppStarter.java:291)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at de.test.BootstrapperIntentService.start(BootstrapperIntentService.java:212)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at de.test.BootstrapperIntentService.onHandleIntent(BootstrapperIntentService.java:66)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:148)
10-12 16:31:54.183 3428-3456/? E/AndroidRuntime:     at android.os.HandlerThread.run(HandlerThread.java:61)

Since I had the correct permission this seems to be a bug on API 23. Is there a workaround for this problem?

stephan1002
  • 447
  • 2
  • 5
  • 11

0 Answers0