java.lang.SecurityException:getDeviceId:用户10058和当前进程都没有android.permission.READ_PHONE_STATE

时间:2015-10-12 14:38:25

标签: java android android-studio

此问题仅发生在API级别23我使用API​​ 16和API 22测试了我的代码没有任何问题。

我在AndroidManifest中使用:

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

在我的代码中我做了:

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

在API23上运行此代码时出现以下错误:

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)

由于我获得了正确的权限,这似乎是API 23上的一个错误。这个问题是否有解决方法?

0 个答案:

没有答案