发短信(带发送状态和到达状态)
来源:互联网 发布:mysql 字段排序 编辑:程序博客网 时间:2024/05/08 09:09
模拟器测试中文可能有乱码,这个与模拟器本身编码有关,换到真机就好了。
权限
<uses-permission android:name="android.permission.SEND_SMS" />
import android.app.Activity;
import android.app.PendingIntent;import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.telephony.SmsManager;
import android.util.Log;
import android.widget.Toast;
public class MyService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
public void onCreate() {
super.onCreate();
sendSMS();
}
public void onDestroy() {
super.onDestroy();
Log.d("keke", "服务销毁");
}
private void sendSMS() {
String phone="5554";
String message="test";
SmsManager sms = SmsManager.getDefault();// 通过SmsManager类的静态方法得到一个类的实例对象
String SENT_SMS_ACTION = "SENT_SMS_ACTION";
String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION";
// create the sentIntent parameter
Intent sentIntent = new Intent(SENT_SMS_ACTION);
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent,
0);
// create the deilverIntent parameter
Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION);
PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0,
deliverIntent, 0);
// register the Broadcast Receivers
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context _context, Intent _intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(),
"SMS sent success actions", Toast.LENGTH_SHORT)
.show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(),
"SMS generic failure actions", Toast.LENGTH_SHORT)
.show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast
.makeText(getBaseContext(),
"SMS radio off failure actions",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(),
"SMS null PDU failure actions", Toast.LENGTH_SHORT)
.show();
break;
}
}
}, new IntentFilter(SENT_SMS_ACTION));
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context _context, Intent _intent) {
Toast.makeText(getBaseContext(), "SMS delivered actions",
Toast.LENGTH_SHORT).show();
}
}, new IntentFilter(DELIVERED_SMS_ACTION));
sms.sendTextMessage(phone, null, message, sentPI, deliverPI);// 这是这个类发短信的方法
}
}
- 发短信(带发送状态和到达状态)
- android短信发送,和状态
- 短信发送状态监听
- 监控监控状态发送短信
- 发送并监听短信状态
- android发送短信以及监听发送状态
- Android发送短信以及监听发送状态
- Android发送短信以及监听发送状态
- Android发送短信并监测发送状态
- 接收短信(利用广播)发送短信(检测发送成功的状态需要利用广播)
- 移动发送短信的状态报告
- 移动发送短信的状态报告
- 短信发送后的状态判断
- 移动发送短信的状态报告
- 短信发送和存入发件箱-区分长短信-发送状态监听获取数据
- 两个android模拟器实现打电话发短信的模拟状态
- 两个android模拟器实现打电话发短信的模拟状态
- android 模拟器 实现 打电话 发短信的模拟状态
- Windows下远程链接HBASE SHELL无法backspace和del的解决
- 10053事件
- 前端工程师?前端攻城湿?前端攻城师?前端攻城狮?
- OMXCodec::read()已经两次遇到等待不到锁而卡死的情况
- 线程
- 发短信(带发送状态和到达状态)
- CET-6 English Words
- Ubuntu开启ssh服务
- Tumblr:150亿月浏览量背后的架构挑战
- 虚拟机 "\\.\Global\vmx86": 系统找不到指定的文件.
- php 与mysql交互的存储过程
- TEM-4 English Words
- wpa_supplicant移植与使用
- 【翻译】(8)CPU ARM Neon