android push:Android短消息推送启动应用程序(SMS PUSH)(BroadCastReceiver)
来源:互联网 发布:python tf idf 编辑:程序博客网 时间:2024/06/06 18:47
转自:http://www.cxybl.com/html/android/20121109/33727.html
程序通过BroadCastReceiver监听短消息,并判断短信的号码,当满足预设号码时,启动一个Activity。 SmsReceiverActivity.java package com.zeph.android.sms.receiver; import android.app.Activity; import android.content.Intent; import android.os.Bundl
-
-
程序通过BroadCastReceiver监听短消息,并判断短信的号码,当满足预设号码时,启动一个Activity。SmsReceiverActivity.java
package com.zeph.android.sms.receiver;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
/**
*
* @author BenZeph
*
*/
public class SmsReceiverActivity extends Activity {
private TextView myTextView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
String message = intent.getStringExtra("MESSAGE");
myTextView = (TextView) findViewById(R.id.myTextView);
myTextView.setText(message);
}
}
程序的重点在BroadCastReceiver
SmsBroadCastReceiver.java
package com.zeph.android.sms.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
/**
*
* @author BenZeph
*
*/
public class SmsBroadCastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String phoneNum = "";
StringBuilder sb = new StringBuilder();
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] myObjectPuds = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[myObjectPuds.length];
for (int i = 0; i < myObjectPuds.length; i++)
messages[i] = SmsMessage
.createFromPdu((byte[]) myObjectPuds[i]);
for (SmsMessage currentMessage : messages) {
sb.append("消息来自:\n");
sb.append(currentMessage.getDisplayOriginatingAddress());
phoneNum = currentMessage.getDisplayOriginatingAddress();
sb.append("\n短消息内容\n");
sb.append(currentMessage.getDisplayMessageBody()); } }
if (phoneNum.equals(09681000631))
{ Intent intentNewTask = new Intent(context, SmsReceiverActivity.class); intentNewTask.putExtra(MESSAGE, sb.to
-
-
sb.append(currentMessage.getDisplayMessageBody());}
}
if (phoneNum.equals("09681000631")) {
Intent intentNewTask = new Intent(context,
SmsReceiverActivity.class);
intentNewTask.putExtra("MESSAGE", sb.toString());
intentNewTask.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentNewTask);
}
}
}
Manifest要注册Receiver,同时提供短消息的User-Permission
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zeph.android.sms.receiver"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".SmsReceiverActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="SmsBroadCastReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
</application>
</manifest>
- Android短消息推送启动应用程序(SMS PUSH)(BroadCastReceiver)
- android push:Android短消息推送启动应用程序(SMS PUSH)(BroadCastReceiver)
- J2ME SMS PUSH 短消息推送
- Android push (一):SMS push
- Android push (一):SMS push
- Android Push消息推送
- Android Push消息推送
- 关于android推送服务器Androidpn(Android push notification)
- Netty实现服务器推Push(Android推送)
- Android开发 消息推送 Push
- Android Push Notificatioin Service(Android消息推送)
- Android--Android 推送 Push开源解决方案
- parse push 消息推送学习笔记(Android消息推送解决方案 备选)
- Flume数据推送(Push)
- 消息推送(Server Push)
- 消息推送(push原理)
- Android Push Notification实现信息推送使用
- Android Push Notification实现信息推送使用
- GBS文件配置概述
- C语言有符号数与无符号数之间的转换
- Oracle 学习笔记14 —— 函数
- ubuntu install apache+php+mysql
- SSE4.1指令集系列之一
- android push:Android短消息推送启动应用程序(SMS PUSH)(BroadCastReceiver)
- 浙江传媒学院实践周成果——我的音乐库管理
- Android紫衫龙王之Activity
- C++实现单链表常用功能(不带头结点)
- HDU 2579 Dating with girls(2) BFS 又一种新的搜索类型 很好的题
- 卡特兰数
- js和jquery获取父级元素、子级元素、兄弟元素的方法
- 通知的通知处理函数(一般以回调实现)
- POSIX 线程取消点的 Linux 实现