我设计了自己的发送短信的撰写屏幕, 在单击发送按钮时 我正在向多个接收者发送消息
sendBTN.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
avedPhoneno = "5558,5554,5556";
StringTokenizer st = new StringTokenizer(savedPhoneno, ",");
while (st.hasMoreElements()) {
tempMobileNumber = (String) st.nextElement();
System.out.println("tempMobileNumber in onclicklistener "+tempMobileNumber);
if (tempMobileNumber.length() > 0
&& encryptedText.toString().trim().length() > 0) {
sendSMS(tempMobileNumber,
base64msgString.concat(timeStamp1));
} else {
Toast.makeText(getBaseContext(),
"Please enter both phone number and message.",
Toast.LENGTH_SHORT).show();
}
}
和发送短信的方法是
private void sendSMS(String edittextSmsNumber, String msg) {
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SMS_SENT), 0);
PendingIntent DeliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(SMS_DELIVERED), 0);
SmsManager sms = SmsManager.getDefault();
// short port = 8888;
sms.sendTextMessage(edittextSmsNumber, null, msg, sentPI, DeliveredPI);
}
在广播接收器中我试图将数据存储到数据库中
private BroadcastReceiver sendreceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
String info = "Send information: ";
switch(getResultCode())
{
case Activity.RESULT_OK:
info += "send successful";
smsSent = true;
if (senderinfo != null && timeStamp != 0 && msgString != null) {
System.out.println("entered into database");
System.out.println("tempMobileNumber is "
+ tempMobileNumber);
outboxDatabase.open();
outboxDatabase.insertintoOutbox(msgString, key,
tempMobileNumber, timeStamp);
outboxDatabase.close();
}
//unregisterReceiver(this);
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
info += "send failed, generic failure";
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
info += "send failed, no service";
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
info += "send failed, null pdu";
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
info += "send failed, radio is off";
break;
}
Toast.makeText(getBaseContext(), info, Toast.LENGTH_SHORT).show();
}
};
但我能够存储最后一个数字,即5556只在数据库中存储三次。
我想将所有三个数字存储到数据库中。 我只想在正确发送消息时存储
即,getResultCode() = Activity.RESULT_OK;
能够发送到三个数字,但只能存储在数据库中
如何克服这一点。