For Android SMS broadcast recipient support, Google should be in Android 4.2 after the weakening, that is, the configuration is more troublesome only, but in the 5.0 should be completely unsupported. Because Google believes that this technology has a great impact on user privacy, in fact it is so, hackers can easily get the user's text messages.
Below, write a small demo of SMS filtering.
/** Create a message receiver that inherits the broadcast recipient * / Public class smsreceiver extends broadcastreceiver { @Override Public void OnReceive(context context, Intent Intent) {System.out.println ("The message arrived .... "); Object[] Objs = (object[]) Intent.getextras (). Get ("PDUs"); for(Object Obj:objs) {//Get SMS ObjectSmsmessage smsmessage = SMSMESSAGE.CREATEFROMPDU ((byte[]) obj); String BODY = Smsmessage.getmessagebody (); String sender = Smsmessage.getoriginatingaddress (); System.out.println ("Body:"+ body); System.out.println ("Sender:"+ sender);//terminates the current broadcast. if("5556". Equals (Sender) {abortbroadcast (); } } }}
The corresponding permissions need to be configured in the Androidmanifest.xml:
<?xml version= "1.0" encoding= "Utf-8"?><manifest xmlns:android="Http://schemas.android.com/apk/res/android" package ="Com.itheima.smsreceiver"android:versioncode="1"android: Versionname="1.0" > <uses-sdkandroid:minsdkversion="8"android:targetsdkversion="17" /> <uses-permission android:name="Android.permission.RECEIVE_SMS"/> <uses-permission android:name="Android.permission.PROCESS_OUTGOING_CALLS" /> <applicationandroid:allowbackup="true"android:icon="@drawable/ Ic_launcher "android:label=" @string/app_name "android:theme=" @style/apptheme " > <activityandroid:name="com.itheima.smsreceiver.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.itheima.smsreceiver.SmsReceiver"> <intent-filter android:priority="+"> <action android:name="Android.provider.Telephony.SMS_RECEIVED"/> </intent-filter> </receiver> <!--configuring broadcast recipients -- <receiver android:name="Com.itheima.smsreceiver.OutCallReceiver"> <intent-filter android:priority="+"> <!--Configure the event that the broadcast recipient cares about is outgoing calls-- <action android:name="Android.intent.action.NEW_OUTGOING_CALL"/> </intent-filter> </receiver> </Application></manifest>
Then analog to send text messages to the mobile phone, you can intercept text messages.
Log information:
Android SMS Filter Applet