标签:android broadcastreceiver sms
说明: 接受短信广播,由Intent解析出短信内容明文, intent中的短信时已pud形式传出的,即byte[][]二位数组,
需要转化出明文SmsMessage.createFromPdu(pdus[i])
广播接收器:
public class SmsReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.getAction() != null) {
if (intent.getAction().equals(Intents.SMS_RECEIVED_ACTION)) {
SmsMessage[] msgs = getMessagesFromIntent(intent);
// to use this SmsMessage
String messageBody = "";
for (SmsMessage message : messages) {
messageBody += message.getMessageBody();
}
Log.i("MSG", messageBody);
}
}
}
/**
* Read the PDUs out of an {@link #SMS_RECEIVED_ACTION} or a}
注意: manifest中声明权限:
<uses-permission android:name="android.permission.RECEIVE_SMS" /> //接收短信必须的权限
<uses-permission android:name="android.permission.READ_SMS"/> //读系统短信权限
<uses-permission android:name="android.permission.WRITE_SMS"/>//写系统短信权限
标签:android broadcastreceiver sms
原文地址:http://blog.csdn.net/zhanghao_hulk/article/details/45367891