我正在开发一个自动回复 android 应用程序,如果它与所选号码匹配,即保存在数据库中,它将向传入号码发送消息。它运行成功,但有时会发送两次消息,它会向该传入号码发送三条消息。
我正在使用以下代码:
void processCall(String inNumber, String msg) {
try {
String sent = "android.telephony.SmsManager.STATUS_ON_ICC_SENT";
PendingIntent pisent = PendingIntent.getBroadcast(getBaseContext(),0, new Intent(sent), 0);
PendingIntent pidel = PendingIntent.getBroadcast(getBaseContext(),0, new Intent("Dilivered"), 0);
SmsManager man = SmsManager.getDefault();
//ArrayList<String> smstext = man.divideMessage(msg);
man.sendTextMessage(inNumber, null, msg, pisent, null);
//man.sendMultipartTextMessage(inNumber, null, smstext, null, null);
Toast.makeText(getBaseContext()," msg send successfully to " + inNumber, Toast.LENGTH_SHORT).show();
ContentValues sentSms = new ContentValues();
sentSms.put(TELEPHON_NUMBER_FIELD_NAME, inNumber);
sentSms.put(MESSAGE_BODY_FIELD_NAME, msg);
ContentResolver contentResolver = getContentResolver();
contentResolver.insert(SENT_MSGS_CONTET_PROVIDER, sentSms);
return;
}
catch (Exception e) {
Toast.makeText(getApplicationContext(), "SMS faild, please try again later!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
我哪里做错了?任何帮助是极大的赞赏。