发送并监听短信状态
来源:互联网 发布:游戏动画软件 编辑:程序博客网 时间:2024/04/30 00:55
这是从其它网站引过来的一段代码,主要是用来监听短信接收和发送情况
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;
}
}
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button btn = new Button(this);
btn.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
sendSMS();
}
});
textView = new TextView(this);
textView.setBackgroundColor(0xffffffff);
textView.setTextColor(0xff0000ff);
textView.setText("SMS processing...");
btn.setText("发送短信");
LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
LinearLayout linear = new LinearLayout(this);
linear.setOrientation(LinearLayout.VERTICAL);
linear.setLayoutParams(textParams);
linear.addView(btn);
linear.addView(textView);
setContentView(linear);
sendReceiver = new SMSReceiver();
IntentFilter sendFilter = new IntentFilter(ACTION_SMS_SEND);
registerReceiver(sendReceiver, sendFilter);
deliveryReceiver = new SMSReceiver();
IntentFilter deliveryFilter = new IntentFilter(ACTION_SMS_DELIVERY);
registerReceiver(deliveryReceiver, deliveryFilter);
}
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);
}
protected void onPaused() {
unregisterReceiver(sendReceiver);
unregisterReceiver(deliveryReceiver);
}
}
听别人说联通的没有deliverly事件,移动的有
和 http://blog.csdn.net/actual_/article/details/6653637 可完成群发,并监听每条短信发送状态
- 发送并监听短信状态
- 短信发送状态监听
- Android监听SMS发送状态并获取短信服务中心号码
- Android监听SMS发送状态并获取短信服务中心号码
- Android监听SMS发送状态并获取短信服务中心号码
- Android监听SMS发送状态并获取短信服务中心号码
- Android监听SMS发送状态并获取短信服务中心号码
- android发送短信以及监听发送状态
- Android发送短信以及监听发送状态
- Android发送短信以及监听发送状态
- Android发送短信并监测发送状态
- Android发送短信,并监听短信发送后是否发送成功的实现方法
- android发送短信并监听插入收件箱的方法
- android 实现监听短信接收并将当前位置发送出去
- Android监听发送短信
- 短信发送和存入发件箱-区分长短信-发送状态监听获取数据
- 在Android中发送短信和彩信,监听短信并显示
- 在Android中发送短信和彩信,监听短信并显示
- 字符串处理函数源码
- rdlc reportviewer vs2010报表 实现导出和web页面显示每页都带表头
- jqGrid asp.net mvc 使用
- debian源
- HDU 3791 二叉搜索树
- 发送并监听短信状态
- 产品不要被技术绑架的十大注意事项
- CVS安装及配置
- 使用SWFUpload上传文件
- oracle表空间和用户创建
- Delphi第三方控件安装卸载指南
- rails migration tutorial
- C# new virtual override 之间的区别
- 如何确定服务器上面网口连接情况