当我从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)
答案 0 :(得分:0)
检查您在清单文件中正确添加的权限。 其次检查你的接收器的意图过滤器是否已正确添加。
答案 1 :(得分:0)
在Manifest.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE_PERMISSION"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
,然后要求它们相同:
final static int REQUESTCODE_PERMISSION_SMS = 301;
if (Build.VERSION.SDK_INT >= 28) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS, Manifest.permission.READ_PHONE_STATE_PERMISSION}, REQUESTCODE_PERMISSION_SMS);
} else {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS}, REQUESTCODE_PERMISSION_SMS);
}