博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
发送短信,判断回执[转]
阅读量:5856 次
发布时间:2019-06-19

本文共 2635 字,大约阅读时间需要 8 分钟。

 
private
void
sendSMS() {
String smsAddress
=
"
10086
"
;
String smsBody
=
"
bylcx
"
;
SmsManager smsMag
=
SmsManager.getDefault();
Intent sendIntent
=
new
Intent(ACTION_SMS_SEND);
PendingIntent sendPI
=
PendingIntent.getBroadcast(
this
,
0
, sendIntent,
0
);
Intent deliveryIntent
=
new
Intent(ACTION_SMS_DELIVERY);
PendingIntent deliveryPI
=
PendingIntent.getBroadcast(
this
,
0
,
deliveryIntent,
0
);
smsMag.sendTextMessage(smsAddress,
null
, smsBody, sendPI, deliveryPI);
}
 
package
lab.sodino.smslistener;
import
android.app.Activity;
import
android.app.PendingIntent;
import
android.content.BroadcastReceiver;
import
android.content.Context;
import
android.content.Intent;
import
android.content.IntentFilter;
import
android.os.Bundle;
import
android.telephony.gsm.SmsManager;
import
android.view.View;
import
android.view.ViewGroup.LayoutParams;
import
android.widget.Button;
import
android.widget.LinearLayout;
import
android.widget.TextView;
public
class
SmsAct
extends
Activity {
private
TextView textView;
private
static
String ACTION_SMS_SEND
=
"
lab.sodino.sms.send
"
;
private
static
String ACTION_SMS_DELIVERY
=
"
lab.sodino.sms.delivery
"
;
private
SMSReceiver sendReceiver;
private
SMSReceiver deliveryReceiver;
public
class
SMSReceiver
extends
BroadcastReceiver {
public
void
onReceive(Context context, Intent intent) {
String actionName
=
intent.getAction();
int
resultCode
=
getResultCode();
if
(actionName.equals(ACTION_SMS_SEND)) {
switch
(resultCode) {
case
Activity.RESULT_OK:
textView.append(
"
\n[Send]SMS Send:Successed!
"
);
break
;
case
SmsManager.RESULT_ERROR_GENERIC_FAILURE:
textView
.append(
"
\n[Send]SMS Send:RESULT_ERROR_GENERIC_FAILURE!
"
);
break
;
case
SmsManager.RESULT_ERROR_NO_SERVICE:
textView
.append(
"
\n[Send]SMS Send:RESULT_ERROR_NO_SERVICE!
"
);
break
;
case
SmsManager.RESULT_ERROR_NULL_PDU:
textView.append(
"
\n[Send]SMS Send:RESULT_ERROR_NULL_PDU!
"
);
break
;
case
SmsManager.RESULT_ERROR_RADIO_OFF:
break
;
}
}
else
if
(actionName.equals(ACTION_SMS_DELIVERY)) {
switch
(resultCode) {
case
Activity.RESULT_OK:
textView.append(
"
\n[Delivery]SMS Delivery:Success!
"
);
break
;
case
SmsManager.RESULT_ERROR_GENERIC_FAILURE:
textView
.append(
"
\n[Delivery]SMS Delivery:RESULT_ERROR_GENERIC_FAILURE!
"
);
break
;
case
SmsManager.RESULT_ERROR_NO_SERVICE:
textView
.append(
"
\n[Delivery]SMS Delivery:RESULT_ERROR_NO_SERVICE!
"
);
break
;
case
SmsManager.RESULT_ERROR_NULL_PDU:
textView
.append(
"
\n[Delivery]SMS Delivery:RESULT_ERROR_NULL_PDU!
"
);
break
;
case
SmsManager.RESULT_ERROR_RADIO_OFF:
textView
.append(
"
\n[Delivery]SMS Delivery:RESULT_ERROR_RADIO_OFF!
"
);
break
;
}
}
}
}

转载地址:http://yrajx.baihongyu.com/

你可能感兴趣的文章
matlab 规律,01用PYTHON下载数据,而后用MATLAB编程探讨规律
查看>>
php 发布拼多多,拼多多补贴换增长的故事还能讲多久?
查看>>
matlab实现zca去白化,白化算法
查看>>
vs环境c++语言教学视频,基于VS Code的C++语言的构建调试环境搭建指南
查看>>
android 字符串转浮点,Android String类型转换为float、double和int的工具类方法
查看>>
android mobile wifi,华为mobile wifi 2下载-HUAWEI Mobile WiFi 2 安卓版v9.0.1.323-PC6安卓网
查看>>
android fragment共享监听,Android Fragment中监听事件
查看>>
android蓝牙交互,Android蓝牙通信app
查看>>
将pyecharts的html页面,使用pyecharts生成Echarts网页的实例
查看>>
GoldenGate组态(四)它veridata组态
查看>>
C#设计模式之十六观察者模式(Observer Pattern)【行为型】
查看>>
Linux学习笔记之九————ubuntu软件安装与卸载
查看>>
Xshell终端模拟器如何查找字符串
查看>>
Linux安装codis
查看>>
搭建开发环境
查看>>
sublime text 3 设置默认自动换行
查看>>
WPF使用cefsharp 下载地址
查看>>
iOS 11开发教程(十六)iOS11应用视图之删除空白视图
查看>>
图像滤镜艺术---Hudson滤镜(Instagram)
查看>>
require.js使用
查看>>