如何将短信发送到1个以上的号码?

cod*_*e22 3 sms android

我想要一个联系号码列表.

我想知道有没有办法在Android中以程序方式向1个以上的号码发送短信?

如果是这样的话?

Mat*_*udy 9

您无法通过Intent执行此操作,因为Android SMS应用程序不允许多个收件人.

您可以尝试使用该SmsManager课程.

首先,您需要android.permission.SEND_SMS在AndroidManifest中申请权限.

然后你可以沿着这些方向做点什么.

// you need to import the Sms Manager
import android.telephony.SmsManager;

// fetch the Sms Manager
SmsManager sms = SmsManager.getDefault();

// the message
String message = "Hello";

// the phone numbers we want to send to
String numbers[] = {"555123456789", "555987654321"};

for(String number : numbers) {
  sms.sendTextMessage(number, null, message, null, null);
}
Run Code Online (Sandbox Code Playgroud)


更新:添加了如何拆分以逗号分隔的字符串

// string input by a user
String userInput = "122323,12344221,1323442";

// split it between any commas, stripping whitespace afterwards
String numbers[] = userInput.split(", *");
Run Code Online (Sandbox Code Playgroud)

  • 这段代码不起作用..因为你的for循环比消息发送过程运行得快..所以在循环中你告诉`SmsManager`发送sms,而它正忙于发送以前的短信 (2认同)

Shi*_*mar 6

对于团体短信或多个短信使用此

  Intent i = new Intent(android.content.Intent.ACTION_VIEW);
    i.putExtra("address", "987385438; 750313; 971855;84393");
    i.putExtra("sms_body", "Testing you!");
    i.setType("vnd.android-dir/mms-sms");
    startActivity(i);
//use permission: <uses-permission android:name="android.permission.SEND_SMS"/>
Run Code Online (Sandbox Code Playgroud)

您可以使用您的联系电话修改“ 9873854; 750313; 971855; 84393”