Android SMS blocker and phone blocker

Source: Internet
Author: User

Mainactivity:

Package Com.wyl.bctest;import Android.support.v7.app.actionbaractivity;import Android.content.intent;import Android.content.intentfilter;import Android.os.bundle;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.textview;public Class Mainactivity extends Actionbaractivity {private final static String action_sms_receive = " Android.provider.Telephony.SMS_RECEIVED ";p rivate final static String action_call_out =" Android.intent.action.NEW_ Outgoing_call "; Button btn; Button btn2; Button Btn3; Button Btn4; TextView TV; Bcreceiver re = null, @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); btn = (Button) Findviewbyid (r.id.btn01);//analog send broadcast BTN2 = (button) Findviewbyid ( R.ID.BTN02)///Register Broadcast BTN3 = (button) Findviewbyid (r.id.btn03);//unregister Broadcast BTN4 = (button) Findviewbyid (r.id.btn04); Myonclicklistener L = new Myonclicklistener (); MyOnclickListener2 listen2 = NEW MyOnclickListener2 (); Btn.setonclicklistener (L); Btn2.setonclicklistener (L); Btn4.setonclicklistener (L); Btn3.setonclicklistener (LISTEN2);//unregister broadcast}class Myonclicklistener implements Onclicklistener {@Overridepublic void OnClick (View v) {if (r.id.btn02 = = V.getid ()) {Bcreceiver R = new Bcreceiver (); intentfilter filter = new Intentfilter (); fi Lter.addaction (action_sms_receive); SYSTEM.OUT.PRINTLN ("Registered broadcast interception, BTN02"); MainActivity.this.registerReceiver (R, filter);} else if (R.id.btn01 = = V.getid ()) {Intent Intent = new Intent (); intent.setaction (action_sms_receive); SYSTEM.OUT.PRINTLN ("Send your own broadcasts"); MainActivity.this.sendBroadcast (intent);} else if (r.id.btn03 = = V.getid ()) {Bcreceiver R = new Bcreceiver (); MainActivity.this.unregisterReceiver (r);} else if (r.id.btn04 = = V.getid ()) {//Intercept phone call out//android.intent.action.NEW_OUTGOING_CALLBCReceiver2 r04 = NEW BCReceiver2 () ; Intentfilter filter = new Intentfilter (); filter.addaction (action_call_out); MainActivity.this.registerReceiver (r04, filter);}}} Class MyonclIckListener2 implements Onclicklistener {@Overridepublic void OnClick (View v) {System.out.println ("Listen2, unregister broadcast"); MainActivity.this.unregisterReceiver (re);}}}

SMS corresponding receiver,

Package Com.wyl.bctest;import Android.content.broadcastreceiver;import Android.content.context;import Android.content.intent;import Android.os.bundle;import Android.telephony.gsm.smsmanager;import Android.telephony.gsm.smsmessage;public class Bcreceiver extends Broadcastreceiver {public bcreceiver () {//TODO Auto-generated Constructor StubSystem.out.println ("Bcreceiver Message Builder ... ");} @Overridepublic void OnReceive (Context arg0, Intent Intent) {//TODO auto-generated method StubSystem.out.println (" Onreceiver SMS Replication Method .... "); Bundle bundle = Intent.getextras (); Object messages[] = (object[]) bundle.get ("PDUs"); Smsmessage msmsmessage[] = new Smsmessage[messages.length];for (int i = 0; i < messages.length; i++) {Msmsmessage[i] = SMSMESSAGE.CREATEFROMPDU ((byte[]) messages[i]);} SYSTEM.OUT.PRINTLN ("Specific content of SMS" +msmsmessage.tostring ());}}

Phone intercept related receiver,

Package Com.wyl.bctest;import Android.content.broadcastreceiver;import Android.content.context;import Android.content.intent;public class BCReceiver2 extends Broadcastreceiver{public BCReceiver2 () {//TODO auto-generated Constructor StubSystem.out.println ("Bcreceiver phone blocker constructor ... ");} @Overridepublic void OnReceive (Context arg0, Intent arg1) {//TODO auto-generated method StubSystem.out.println (" Onreceiver phone intercept replication method .... ");}}

The point of attention is:

1. Register for SMS receive and call out permissions in Androidmainfest.xml.

2. When registering interception in Java Code intentfilter filter, where filter.addaction (param) parameters param equivalent to androidmainfest.xml in the

<receiver android:name= "Com.wyl.jqr.TestReceiver" ><intent-filter><action android:name= " Android.intent.action.EDIT "/><action android:name=" Android.provider.Telephony.SMS_RECEIVED "/></ Intent-filter></receiver>

  

android.provider.telephony.sms_received this string literal, 
The entire configuration of the Androidmainifest.xml is as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" Com.wyl.bctest "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk A ndroid:minsdkversion= "8" android:targetsdkversion= "/><uses-permission android:name=" Android.permission.RECEIVE_SMS "/><!--increase access to intercept calls--><uses-permission android:name=" Android.permission.PROCESS_OUTGOING_CALLS "/> <application android:allowbackup=" true "android:icon=" @drawable/ic_launcher "android:label=" @string/app_name "android:theme=" @style/apptheme "> <acti Vity android:name= "com.wyl.bctest.MainActivity" android:label= "@string/app_name" > &lt ;intent-filter> <action android:name= "Android.intent.action.MAIN"/> <category A  Ndroid:name= "Android.intent.category.LAUNCHER"/> </intent-filter>      </activity> <!--<receiver android:name= "Com.wyl.bctest.BCReceiver" ></receiver> </application></manifest>

  

Android SMS blocker and phone blocker

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.