[android开发]发送短信
来源:互联网 发布:java o2o 商城源码 编辑:程序博客网 时间:2024/05/03 15:58
发送单条短信:
private void sendSingleSms(String phone, String content) {SmsManager smsManager = SmsManager.getDefault();List<String> texts = smsManager.divideMessage(content);// 发送之前检查短信内容是否为空for (int i = 0; i < texts.size(); i++) {String text = texts.get(i);Intent itSend = new Intent(INTENT_SEND_STATE);PendingIntent mSendPI = PendingIntent.getBroadcast(getApplicationContext(), 0, itSend, PendingIntent.FLAG_ONE_SHOT);// 这里requestCode和flag的设置很重要,影响数据KEY_PHONENUM的传递。smsManager.sendTextMessage(phone, null, content, mSendPI, null);}}
关于上面的sendTextMessage方法的第三个参数mSendPI, 它是短信发送结果的一个返回, 当短信 发送成功/发送失败 的时候就会执行该 PendingIntent, 我这里是让他发送一个广播.
广播接收器:
private BroadcastReceiver receiver = new BroadcastReceiver() {@Overridepublic void onReceive(Context context, Intent intent) {if (getResultCode() == RESULT_OK)success_count++;elsefail_count++;setSendTitle(success_count, fail_count);if ((success_count + fail_count) == phone_numbers.size()) {showToast("短信已全部发送");}}};
RESULT_OK即成功, 否则是失败.
另外附上发送多条短信的方法:
private void sendSms(ArrayList<String> phone_numbers, String content) {try {runOnUiThread(new Runnable() {@Overridepublic void run() {setSendTitle(success_count, fail_count);}});for (String phone_number : phone_numbers) {sendSingleSms(phone_number, content);}} catch (Exception e) {showToast("获取权限失败");}}
0 0
- [android开发]发送短信
- Android开发短信发送
- Android开发之短信发送
- android 开发 短信发送器
- Android开发之发送短信
- Android(开发):发送短信
- android开发 - 短信发送器
- Android开发《二》短信发送
- Android开发(一)发送短信程序
- Android开发5:短信发送器
- Android开发(一)发送短信程序
- Android开发之发送短信程序
- android开发之发送短信SMS
- Android开发入门之发送短信
- 【Android 开发教程】使用Intent发送短信
- Android开发--电话拨号、短信发送
- Android开发案例之短信发送器
- Android开发之接收和发送短信
- 交互数据解析之JSON解析
- 【创业家】汽车后万亿市场即将爆发,谁是最后赢家?
- 123445466
- iOS8 程序 系统设置-定位服务-崩溃问题
- 日经社説 20150305 課題点検し電力・ガス改革を成功に導け
- [android开发]发送短信
- sizeof与strlen()、递归优化题解
- 八大排序算法之选择排序
- 分享一个很实用的java代码,可以将以逗号分隔的数字以从大到小的方式排序后返回
- APP启动引导页实现方式
- 推荐两款使用的html5播放器
- Exchange2010安装配置
- 绕过const限定符所出现的不可思议情况
- c#自定义事件的使用方法