標籤:提示 .net odi rac get creat over public manifest
轉載請註明出處:http://blog.csdn.net/l1028386804/article/details/46994097
這裡。向大家簡介通過BroadcastReceiver來攔截簡訊的方法
1、建立簡訊廣播接收者SmsRecevier
這個類是BroadcastReceiver的子類,詳細的攔截操作在這個類中實現。我在這裡僅僅是簡單的介紹一下方法,把擷取到的簡訊列印資訊出來。
詳細的商務邏輯就要大家自己去實現了。
詳細代碼例如以下:
package com.lyz.receiver;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.telephony.SmsMessage;import android.util.Log;/** * 簡訊廣播接收者 * @author liuyazhuang * */public class SmsRecevier extends BroadcastReceiver {private static final String TAG = "SmsRecevier";@Overridepublic void onReceive(Context context, Intent intent) {Object[] pdus = (Object[]) intent.getExtras().get("pdus");for(Object pdu:pdus){SmsMessage smsMessage = SmsMessage.createFromPdu((byte[])pdu);String body = smsMessage.getDisplayMessageBody();Log.i(TAG, body);}}} 2、注冊授權資訊
詳細實現例如以下:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.lyz.sms" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <uses-permission android:name="android.permission.RECEIVE_SMS"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.lyz.sms.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- 配置廣播攔截簡訊 --> <receiver android:name="com.lyz.receiver.SmsRecevier"> <intent-filter android:priority="1000"> <action android:name="android.provider.Telephony.SMS_RECEIVED"/> </intent-filter> </receiver> </application></manifest>
大功告成。是不是和《Android之——攔截撥出電話》一樣簡單呢?
溫馨提示:大家能夠到http://download.csdn.net/detail/l1028386804/8921125攔截擷取完整的代碼示範範例
Android之——攔截簡訊