如何发送短信就超过了1号? [英] How to send text message to more than 1 number?

查看:120
本文介绍了如何发送短信就超过了1号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有联系号码清单。

我想知道的是有没有办法在Android中发送短信就超过了1号iprogrammatically?

I want to know is there a way to send a text message to more than 1 number iprogrammatically in Android?

如果又如何?

推荐答案

您无法通过意向做到这一点,由于Android的短信应用不允许多个收件人。

You can't do this via Intent, as the android SMS app doesn't allow multiple recipients.

您可以尝试使用 SmsManager 类。

首先你需要申请许可 android.permission.SEND_SMS 在AndroidManifest的。

First of all you need to request the permission android.permission.SEND_SMS in your AndroidManifest.

然后,你可以做的东西沿着这些路线。

Then you can do something along these lines.

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



更新:新增如何分割一个逗号分隔的字符串


Update: Added how to split a comma-separated string

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

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

这篇关于如何发送短信就超过了1号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆