java.lang.SecurityException: getIccSerialNumber 以你之姓@ 2023-06-10 09:23 6阅读 0赞 ### 问题: ### 需要获取手机SIM读取权限,但是总是读取失败 //手机管理者 TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); simSerialNumber = tm.getSimSerialNumber(); 这是错误信息: Process: chapter05.qst.com.mobileguard, PID: 31915java.lang.RuntimeException: Unable to start activity ComponentInfo{chapter05.qst.com.mobileguard/chapter05.qst.com.mobileguard.activity.Setup2Activity}: java.lang.SecurityException: getIccSerialNumber at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3430) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)at android.os.Handler.dispatchMessage(Handler.java:112)at android.os.Looper.loop(Looper.java:216)at android.app.ActivityThread.main(ActivityThread.java:7625)at java.lang.reflect.Method.invoke(Native Method)at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) Caused by: java.lang.SecurityException: getIccSerialNumber at android.os.Parcel.createException(Parcel.java:1953)at android.os.Parcel.readException(Parcel.java:1921) at android.os.Parcel.readException(Parcel.java:1871) at com.android.internal.telephony.IPhoneSubInfo$Stub$Proxy.getIccSerialNumberForSubscriber(IPhoneSubInfo.java:659) at android.telephony.TelephonyManager.getSimSerialNumber(TelephonyManager.java:2804) at android.telephony.TelephonyManager.getSimSerialNumber(TelephonyManager.java:2787) at chapter05.qst.com.mobileguard.activity.Setup2Activity.initData(Setup2Activity.java:128) at chapter05.qst.com.mobileguard.activity.BaseSetupActivity.onCreate(BaseSetupActivity.java:20) at android.app.Activity.performCreate(Activity.java:7458) at ### 原因: ### 没有设置手机的权限(安卓6.0以上的版本都不能自动读取权限) ### 解决: ### 1.直接手动在手机设置里面为APK打开读取权限,再次运行就可以了 2.可以在项目里面设置权限,使用弹出框让用户自定义权限 参考:[https://www.jianshu.com/p/57798618bd90\#rd][https_www.jianshu.com_p_57798618bd90_rd] [https://www.jianshu.com/p/c17fe97c8924][https_www.jianshu.com_p_c17fe97c8924] ### 总结: ### 这个问题纠结了好长时间,在老师的提醒下终于解决了 [https_www.jianshu.com_p_57798618bd90_rd]: https://www.jianshu.com/p/57798618bd90#rd [https_www.jianshu.com_p_c17fe97c8924]: https://www.jianshu.com/p/c17fe97c8924
相关 java.lang.SecurityException: getIccSerialNumber 问题: 需要获取手机SIM读取权限,但是总是读取失败 //手机管理者 TelephonyManager tm = (Telephony 以你之姓@/ 2023年06月10日 09:23/ 0 赞/ 6 阅读
还没有评论,来说两句吧...