gpt4 book ai didi

Android:一次单击发送多条短信

转载 作者:行者123 更新时间:2023-11-29 16:08:27 25 4
gpt4 key购买 nike

我正在开发一个短信发送应用程序。代码运行良好。我可以从我的应用程序发送短信为此,我使用以下代码作为:

private void sendSMS(String phoneNumber, String message, final int k){   
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";

Intent sentIntent = new Intent(SENT);
Intent deliveredUntent = new Intent(DELIVERED);


PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,sentIntent, 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,deliveredUntent, 0);

//---when the SMS has been sent---
sentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()){
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent "+k,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;
}
}
};

//---when the SMS has been delivered---
deliverReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode()){
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered", Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered", Toast.LENGTH_SHORT).show();
break;
}
}
};

try{
registerReceiver(sentReceiver, new IntentFilter(SENT));
registerReceiver(deliverReceiver, new IntentFilter(DELIVERED));
} catch (Exception e) {
e.printStackTrace();
}

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}

但现在我想向多个号码发送短信。我怎样才能做到这一点。我在 Google 上搜索但没有得到满意的答案。

最佳答案

只需循环包含多个号码的列表并在循环内调用 sms.sendtextmessage

关于Android:一次单击发送多条短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15831336/

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