Android receives SMS messages and shields notification notifications

Source: Internet
Author: User

Package COM. ISS. test; </P> <p> Import android. content. broadcastreceiver; <br/> Import android. content. context; <br/> Import android. content. intent; <br/> Import android. OS. bundle; <br/> Import android. telephony. smsmessage; <br/> Import android. util. log; </P> <p> public class smsreceiveandmask extends broadcastreceiver <br/>{</P> <p> private string tag = "smsreceiveandmask "; <br/> @ override <br/> Public void on Receive (context, intent) {<br/> log. V (TAG, ">>>>>>> onreceive start "); <br/> // Step 1. Obtain the text message content and sender. <br/> stringbuilder body = new stringbuilder (); // text message content <br/> stringbuilder number = new stringbuilder (); // text message sender </P> <p> log. V (TAG, "Number" + number); <br/> bundle = intent. getextras (); <br/> If (bundle! = NULL) {<br/> object [] _ PDUS = (object []) bundle. get ("PDUS"); <br/> smsmessage [] Message = new smsmessage [_ PDUS. length]; <br/> for (INT I = 0; I <_ PDUS. length; I ++) {<br/> message [I] = smsmessage. createfrompdu (byte []) _ PDUS [I]); <br/>}< br/> for (smsmessage currentmessage: Message) {<br/> body. append (currentmessage. getdisplaymessagebody (); <br/> Number. append (currentmessage. getdisplayoriginatingaddress (); <br/>}< br/> string smsbody = body. tostring (); <br/> string smsnumber = number. tostring (); </P> <p> log. V (TAG, "smsnumber" + smsnumber); </P> <p> log. V (TAG, "smsbody" + smsbody); <br/> If (smsnumber. contains ("+ 86") {<br/> smsnumber = smsnumber. substring (3); <br/>}</P> <p> string TMP [] = smsbody. split (";"); </P> <p> for (INT I = 0; I <TMP. length; I ++) <br/>{< br/> system. out. println (TMP [I]); </P> <p> log. V (TAG, "tmp [I]" + TMP [I]); <br/>}</P> <p> // Step 2: check whether the text message meets the filtering conditions. <br/> Boolean flags_filter = true; <br/> If (smsnumber. equals ("10086") {// Block messages sent from 10086 <br/> flags_filter = true; <br/> log. V (TAG, "sms_number.equals (10086)"); <br/>}< br/> // Step 3: Cancel <br/> If (flags_filter) {</P> <p> log. V (TAG, "flags_filter"); <br/> This. abortbroadcast (); <br/>}< br/> log. V (TAG, ">>>>>> onreceive end"); <br/>}</P> <p >}< br/>

 

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <manifest xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> package = "com. ISS. test "Android: versioncode =" 1 "Android: versionname =" 1.0 "> <br/> <application Android: icon =" @ drawable/icon "Android: label = "@ string/app_name"> <br/> <er Android: Name = ". smsreceiveandmask "> <br/> <intent-filter Android: Priority =" 1000 "> <br/> <action Android: Name =" android. provider. telephony. sms_received "/> <br/> </intent-filter> <br/> </er ER> </P> <p> </Application> </P> <p> <uses-Permission Android: name = "android. permission. receive_sms "> </uses-Permission> </P> <p> </manifest>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.