android 发送短信
时间: 2023-10-18 10:57:39 浏览: 99
在Android中发送短信有几种方法可以实现。一种方法是使用Intent隐式调用系统短信应用进行发送。可以使用以下代码来发送短信:
```java
Uri uri = Uri.parse("smsto:10086");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "Hello World!");
startActivity(it);
```
另一种方法是使用SmsManager发送短信。可以使用以下代码来发送短信:
```java
SmsManager sms = SmsManager.getDefault();
List<String> texts = sms.divideMessage("需要发送的短信内容!");
for (String text : texts) {
sms.sendTextMessage("10086", null, text, null, null);
}
```
还有一种发送非文本文件的方法,比如加密数据。可以使用以下代码来发送:
```java
SmsManager smsm = SmsManager.getDefault();
short port = 1000;
PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(), 0);
smsm.sendDataMessage(number, null, port, message.getBytes(), pi, null);
```
这些方法可以根据你的需求选择使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Android 发送短信](https://blog.csdn.net/a451319296/article/details/117857513)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [android 发送短信的两种方式](https://blog.csdn.net/qq_33209777/article/details/94553043)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [android 几种发送短信的方法](https://blog.csdn.net/tianyitianyi1/article/details/18037771)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文