由网友(陪我笑陪我闹)分享简介:我的工作在Android短信application.I需要发送短信到多个contact.There可发送短信到多接触,所以我用loop.The下面的方法是我的code。I am working on an android sms application.I have to send sms to multiple c...
我的工作在Android短信application.I需要发送短信到多个contact.There可发送短信到多接触,所以我用loop.The下面的方法是我的code。
I am working on an android sms application.I have to send sms to multiple contact.There is method available to send sms to multi contacts so i used for loop.The following is my code.
for (int i = 0; i < to_nums.size();i++) {
sendSms(to_nums.get(i), snd_txt.getText().toString() );
}
public void sendSms(final String phoneNumber, final String message){
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED),0);
//--- When the SMS has been sent --
sendBroadcastReceiver=new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
default:
break;
}
context.unregisterReceiver(this);
}
};
registerReceiver(sendBroadcastReceiver , new IntentFilter(SENT));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
但是,当我运行我的code我正在一个例外,那说,接收器未注册。单除非法律它的工作原理Fone公司。 我。怎么可以注册和注销的顺序?请帮我的朋友。
But when I am running my code I am getting an exception ,that says 'Receiver not registered'. for single receipient it works fone. .How can I register and unregister in order? Please help me friends.
推荐答案
您可以看看这些:
Sending短信存储在一个TextView 多个联系人
和
How发送短信到多个联系人和得到的结果code为他们每个人的机器人
和
在安卓发送短信给多人
相关推荐
最新文章