Android Radio-SMS Blocker

Source: Internet
Author: User

Mainactivity.java

Package Com.example.broadcasttest;import Android.content.intent;import Android.content.intentfilter;import Android.os.bundle;import Android.support.v7.app.actionbaractivity;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;public class Mainactivity extends ActionBarActivity { Button Btn01; Button btn02; Button btn03; Button Btn04;private Final static String action_sms = "Android.provider.Telephony.SMS_RECEIVED"; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_ Main); btn01 = (Button) Findviewbyid (r.id.btn01); btn02 = (Button) Findviewbyid (R.ID.BTN02); btn03 = (Button) Findviewbyid (r.id.btn03); btn04 = (Button) Findviewbyid (r.id.btn04); Btn01.setonclicklistener (new Mylistenr ()); Btn02.setonclicklistener (New MyListener2 ()); Btn03.setonclicklistener (new Mylistenr ()); Btn04.setonclicklistener ( New Mylistenr ());} Class Mylistenr implements onclicklistener{@Overridepublic void OnClick (ViEW view) {//TODO auto-generated method Stubif (R.id.btn01==view.getid ()) {//Turn on broadcast intent intent = new intent ();// Intent.setaction (Intent.action_edit);//intent.setaction (Intent.action_search); MainActivity.this.sendBroadcast (intent);} else if (R.id.btn03==view.getid ()) {//Turn on broadcast intent intent = new intent (); intent.setaction (action_sms); System.out.println ("Ready to simulate sending SMS"); MainActivity.this.sendBroadcast (intent);} else if (R.id.btn04==view.getid ()) {//Turn on broadcast TestBCReceiver02 receiver = new TestBCReceiver02 (); System.out.println ("= = Cancel monitoring = ="); MainActivity.this.unregisterReceiver (receiver);//This will cause the app to crash, temporarily unaware of the cause}}}class MyListener2 implements onclicklistener{@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method stub//Register broadcast event//1. Get RecevierTestBCReceiver02 receiver = new TestBCReceiver02 ();//2. Generate a Intentfilter object intentfilter filter = new Intentfilter ();//3. Add an ACTION filter.addaction (action_sms) for Intentfilter; MainActivity.this.registerReceiver (receiver, filter);}}}

Recvier Implementation class:

Package Com.example.broadcasttest;import Android.content.broadcastreceiver;import Android.content.context;import Android.content.intent;public class TestBCReceiver02 extends Broadcastreceiver{public TestBCReceiver02 () { System.out.println ("BC02 's constructor begins, ... ");} @Overridepublic void OnReceive (Context arg0, Intent arg1) {System.out.println ("received SMS");}}

Receiver Implementation Class 2

Package Com.example.broadcasttest;import Android.content.broadcastreceiver;import Android.content.context;import Android.content.intent;public class Testbroadcastreceiver extends Broadcastreceiver{public testbroadcastreceiver () { SYSTEM.OUT.PRINTLN ("Receiver started,,,,");} @Overridepublic void OnReceive (Context arg0, Intent arg1) {System.out.println ("OnReceive .....");}}

  

Android Radio-SMS Blocker

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.