The manifest file defines:
1<receiver android:name= ". Mybroadcastreceiver ">2<intent-filter>3<action android:name= "abc"/>4</intent-filter>5</receiver>6<receiver android:name= ". MyBroadcastReceiver2 ">7<intent-filter>8<action android:name= "abc"/>9</intent-filter>Ten</receiver> One<receiver android:name= ". MyBroadcastReceiver3 "> A<intent-filter> -<action android:name= "abc"/> -</intent-filter> the</receiver>
---------------Mybroadcastreceiver------------------------
1 Public classMybroadcastreceiverextendsBroadcastreceiver {2 PrivateNotificationmanager Manager;3 4 PublicMybroadcastreceiver () {5 //TODO auto-generated Constructor stub6 }7 8 //Dialoog is not used in the broadcast, you can use Notificationmanager9 //the life cycle of the broadcast is OnReceiveTen @Override One Public voidOnReceive (Context context, Intent Intent) { A //TODO auto-generated Method Stub -Manager =(notificationmanager) Context - . Getsystemservice (context.notification_service); theString name = Intent.getstringextra ("name"); -Notificationcompat.builder Builder =NewNotificationcompat.builder ( - context); -Builder.setticker ("The Radio is Coming"); + Builder.setsmallicon (r.drawable.ic_launcher); -Builder.setcontenttitle ("No net"); +Builder.setcontenttext ("WiFi Off" +name); AManager.notify (1001, Builder.build ()); at - //Toast.maketext (context, "Hello" + name, 0). Show (); - - } - -}
-----------------mainactivity------------------------
1 Public classMainactivityextendsactionbaractivity {2 Privatebutton button;3 4 @Override5 protected voidonCreate (Bundle savedinstancestate) {6 Super. OnCreate (savedinstancestate);7 Setcontentview (r.layout.fragment_main);8button =(Button) Findviewbyid (r.id.button1);9Button.setonclicklistener (NewView.onclicklistener () {Ten One @Override A Public voidOnClick (View v) { - //TODO auto-generated Method Stub -Intent intent=NewIntent (); theIntent.setaction ("abc")); -Intent.putextra ("name", "Zy"); - Sendbroadcast (intent); - } + }); - +}
Android starts with the Broadcastreceiver