我卡了很长时间,无法解决。请帮助...我正在尝试从 android 设备以编程方式发送短信。我可以从许多设备成功发送,但不能从一些 android api 级别> = 22 的三星双卡设备发送。对于 api 级别 >=22,我编写了如下代码,
public static final String SMS_SENT_ACTION = "package.name.app.SMS_SENT_ACTION";
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
unregisterReceiver(this);
String message = null;
switch (getResultCode()) {
case Activity.RESULT_OK:
message = "Message Sent Successfully !";
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
message = "Error.";
sendDefaultMessage(default_number, default_send_number, text);
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
message = "Error: No service.";
sendDefaultMessage(default_number, default_send_number, text);
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
message = "Error: Null PDU.";
sendDefaultMessage(default_number, default_send_number, text);
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
message = "Error: Radio off.";
sendDefaultMessage(default_number, default_send_number, text);
break;
}
Toast.makeText(GetAppointment.this, message, Toast.LENGTH_LONG).show();
}
}, new IntentFilter(SMS_SENT_ACTION));
SmsManager.getSmsManagerForSubscriptionId(subscription_id).sendTextMessage(send_number, null, messageToSend, PendingIntent.getBroadcast(
this, 0, new Intent(SMS_SENT_ACTION), 0), null);
没有权限相关的问题,因为短信可以从 api 级别 >=22 的华硕双卡设备和索尼单卡设备发送。
我怎样才能使它适用于所有设备?我非常需要帮助。