SmsManager发送多个消息

时间:2013-04-20 09:05:36

标签: java android sms

我正在开发一个自动回复安卓应用程序,如果它与所选数字匹配,即保存在数据库中,它将向传入号码发送消息。它成功运行但是它会在一段时间内发送消息两次,它会向该传入号码发送三条消息。

我使用以下代码:

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();
    }

我哪里做错了?非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

尝试在两者之间插入日志消息,并查看此函数执行的次数。此外,如果这是一个正在运行的服务,请查看您是否多次触发服务