gpt4 book ai didi

java - SmsManager 发送多条消息

转载 作者:行者123 更新时间:2023-12-01 04:44:01 28 4
gpt4 key购买 nike

我正在开发一个自动回复 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();
}

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

最佳答案

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

关于java - SmsManager 发送多条消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16118556/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com