Android发送多条短信,如何区分返回状态
帖子发表于 :周日 11月 30, 2014 11:56 pm
Android发送多条短信,如何区分返回状态
原文链接
http://bbs.csdn.net/topics/390496405
在发送的时候添加Extra"SEND_SMS_CODE"
原文链接
http://bbs.csdn.net/topics/390496405
在发送的时候添加Extra"SEND_SMS_CODE"
代码: 全选
在广播接受返回状态码的时候区分既可以public void sendSms(String code,String comPhone,String content) {
sentIntent.putExtra("SEND_SMS_NUM", comPhone);
sentIntent.putExtra("SEND_SMS_CONTENT", content);
sentIntent.putExtra("SEND_SMS_CODE", code);
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent,0);
Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION);
PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0,deliverIntent, 0);
Log.w(TAG, "扣费短信编码为----->存储【"+sentIntent.getStringExtra("SEND_SMS_CODE")+"】");
Log.w(TAG, "发送短信--接收手机号码为------>存储【" + sentIntent.getStringExtra("SEND_SMS_NUM") + "】");
Log.w(TAG, "发送短信内容为------>存储【" + sentIntent.getStringExtra("SEND_SMS_CONTENT")+"】");
sms.sendTextMessage(comPhone, null, content, sentPI, deliverPI);
}
代码: 全选
广播接收代码
BroadcastReceiver receiver=new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals("android.provider.Telephony.SMS_SEND"))
{
switch (getResultCode())
{
case Activity.RESULT_OK:
Log.i(TAG, "短信发送成功!------>编号=【"+intent.getStringExtra("SEND_SMS_CODE")+"】<------>号码=【"+intent.getStringExtra("SEND_SMS_NUM")+"】<------>内容=【"+intent.getStringExtra("SEND_SMS_CONTENT")+"】");
break;
default:
Log.i(TAG, "短信发送成功!------>编号=【"+intent.getStringExtra("SEND_SMS_CODE")+"】<------>号码=【"+intent.getStringExtra("SEND_SMS_NUM")+"】<------>内容=【"+intent.getStringExtra("SEND_SMS_CONTENT")+"】");
break;
}
}
}
};
IntentFilter filter=new IntentFilter();
filter.addAction(SENT_SMS_ACTION);
filter.addAction(DELIVERED_SMS_ACTION);
filter.addAction(SMS_RECEIVED);
filter.addCategory(DEFAULT);
filter.setPriority(priority);
this.registerReceiver(receiver, filter);