我在使用Oreo版本发送短信时遇到了安全问题,但在其他Android版本中正常工作。在下面的代码行中出现错误。
sms.sendTextMessage(phoneNumber, null,message, sentPI, deliveredPI);
报告1
> java.lang.SecurityException: at android.os.Parcel.readException
> (Parcel.java:1942) at android.os.Parcel.readException
> (Parcel.java:1888) at
> com.android.internal.telephony.ISms$Stub$Proxy.sendTextForSubscriber
> (ISms.java:955) at
> android.telephony.SmsManager.sendTextMessageInternal
> (SmsManager.java:372) at
> android.telephony.SmsManager.sendTextMessage (SmsManager.java:355)
> at com.moba.attendanceapp.RegistrationandVerify.sendSMS
> (RegistrationandVerify.java:172) at
> com.moba.attendanceapp.RegistrationandVerify.onViewClicked
> (RegistrationandVerify.java:92) at
> com.moba.attendanceapp.RegistrationandVerify$$ViewInjector$1.doClick
> (RegistrationandVerify$$ViewInjector.java:22) at
> butterknife.internal.DebouncingOnClickListener.onClick
> (DebouncingOnClickListener.java:22) at
> android.view.View.performClick (View.java:6267) at
> android.view.View$PerformClick.run (View.java:24763) at
> android.os.Handler.handleCallback (Handler.java:789) at
> android.os.Handler.dispatchMessage (Handler.java:98) at
> android.os.Looper.loop (Looper.java:164) at
> android.app.ActivityThread.main (ActivityThread.java:6548) at
> java.lang.reflect.Method.invoke (Native Method) at
> com.android.internal.os.Zygote$MethodAndArgsCaller.run
> (Zygote.java:240) at com.android.internal.os.ZygoteInit.main
> (ZygoteInit.java:767)
SmsManager
发送消息也需要READ_PHONE_STATE
权限。我还没有在任何设备上确认过这一点,但在模拟器上确实发生了这种情况。据说在8.1中已经修复:https://dev59.com/7FYO5IYBdhLWcg3wEddO。 - Mike M.