我正在尝试开发一个将短信发送到电子邮件地址的应用。使用我的Note 5上的默认消息传递应用程序,我可以输入我的电子邮件地址作为收件人并发送消息没问题。 (我有Sprint。)但是当我尝试在代码中执行此操作时:
Intent intentSent = new Intent(Globals.SENT);
intentSent.putExtra("phoneNumber",phoneNumber);
Intent intentDelivered = new Intent(Globals.DELIVERED);
intentDelivered.putExtra("emailAddress",emailAddress);
PendingIntent sentPI = PendingIntent.getBroadcast(context, 0,
intentSent, 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0,
intentDelivered, 0);
SmsManager sms = SmsManager.getDefault();
if (emailAddress != null && messageBody.length() > 0) {
sms.sendTextMessage(emailAddress, null, messageBody, sentPI, deliveredPI);
}
未调用已发送的接收方,并且消息显示在我的消息传递应用中,因为它已发送到“匿名”并且传递失败。 Delivered接收器确实调用onReceive():
public class SMSDeliveredReceiver extends BroadcastReceiver {
private String TAG = "SMSDeliveredReceiver";
Context context;
@Override
public void onReceive(Context context, Intent intent) {
this.context = context;
Bundle extras = intent.getExtras();
if (extras != null) {
String emailAddress = extras.getString("emailAddress","");
Log.d(TAG,emailAddress );
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(context,"Email received",Toast.LENGTH_LONG).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(context, "SMS not delivered",
Toast.LENGTH_LONG).show();
break;
}
}
}
}
有没有办法成功完成这项工作?这个答案对我没有帮助,因为我想为所有运营商做这件事。 Android: How to send SMS to email account