二、SmsReceiver.java文件如下所示:
站在用戶的角度思考問題,與客戶深入溝通,找到塔河網(wǎng)站設(shè)計(jì)與塔河網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、空間域名、虛擬主機(jī)、企業(yè)郵箱。業(yè)務(wù)覆蓋塔河地區(qū)。package com.example.smslistenerreiceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsMessage;
import android.telephony.gsm.SmsManager;
import android.util.Log;
public class SmsReceiver extends BroadcastReceiver {
private static final String TAG = "SmsReceiver";
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.i(TAG, "短信來了");
Object [] pdus = (Object[]) intent.getExtras().get("pdus");
for(Object pdu :pdus){
SmsMessage sms = SmsMessage.createFromPdu((byte[]) pdu);
String sender = sms.getOriginatingAddress();
String body = sms.getMessageBody();
Log.i(TAG, "發(fā)件人:"+sender);
Log.i(TAG, "短信內(nèi)容:"+body);
if("5566".equals(sender)){
SmsManager sm = SmsManager.getDefault();
sm.sendTextMessage(sender, null, "短信", null, null);
}
}
}
}
三、注意添加接收短信的權(quán)限
四、注冊監(jiān)聽廣播事件