Android Basics Getting Started tutorial--4.3.2 broadcastreceiver discovering
Source: Internet
Author: User
<span id="Label3"></p>Android Basics Getting Started tutorial--4.3.2 broadcastreceiver discovering<p><p>Tags (space delimited): android basics Getting Started Tutorial</p></p>Introduction to this Section: <blockquote> <blockquote> <p>We have a preliminary understanding of Broadcastreceiver in the last section, and we know two types of broadcasting: standard and orderly,<br>Register broadcast receivers dynamically or statically, listen to the system broadcast, and send your own broadcasts! Has met our basic needs ~<br>But the broadcast in front of you is a global broadcast! This also means that our app broadcasts, and other apps will receive it,<br>or other apps sent by the broadcast, our app will also receive, so it is easy to cause some security problems! and<br>Android provides us with a mechanism for local broadcasting, and broadcasts that use this mechanism will only propagate within the app, and<br>Broadcast receivers can only receive broadcasts from this app!</p> </blockquote> </blockquote>1. Local broadcast 1) core usage:<p><p></p></p><p><p><strong>PS: local broadcast cannot be accepted by static registration, more efficient than system global broadcast</strong></p></p>2) precautions:<p><p></p></p>3) code example (elsewhere Landing kick user offline): <blockquote> <blockquote> <p>like, is running, if we use another phone to login to their own account, the front of this is to remind the account<br>Log in at another terminal and then turn off all of the activity we've opened and go back to the landing page.<br>Let's write a simple example:</p> </blockquote> </blockquote><p><p><strong>Run:</strong></p></p><p><p></p></p><p><p><strong>Code implementation:</strong></p></p><p><p><strong>Step 1</strong>: Prepare a activitycollector that closes all activity, before using the one provided by the previous activity!</p></p><p><p><strong>Activitycollector.java</strong></p></p><pre class="prettyprint"><code class="language-Java hljs cs"><span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">class</span></span>Activitycollector {<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span> <span class="hljs-keyword"><span class="hljs-keyword">Static</span></span>list<activity> activities =<span class="hljs-keyword"><span class="hljs-keyword">New</span></span>Arraylist<activity> ();<span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">Static</span></span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">addactivity</span></span>(activity Activity) {activities.add (activity); }<span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">Static</span></span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">removeactivity</span></span>(activity Activity) {activities.remove (activity); }<span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">Static</span></span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">Finishall</span></span>() {<span class="hljs-keyword"><span class="hljs-keyword"></span> for</span>(Activity activity:activities) {<span class="hljs-keyword"><span class="hljs-keyword">if</span></span>(!activity.isfinishing ()) {activity.finish (); } } }}</code></pre><p><p><strong>Step 2</strong>: First write to the simple baseactivity, used to inherit, and then write down the landing screen!</p></p><p><p><strong>Baseactivity.java</strong></p></p><pre class="prettyprint"><code class="language-Java hljs java"><code class="language-java hljs Java"><span class="hljs-keyword">public </span> <span class="hljs-class"><span class="hljs-keyword">class </span> <span class="hljs-title">baseactivity </span> <span class="hljs-keyword"> Extends </span> <span class="hljs-title">appcompatactivity </span> {</span> <span class="hljs-annotation"> @Override </span> <span class="hljs-keyword">protected </span> <span class="hljs-keyword">void </span> <span class="hljs-title">oncreate </span> (Bundle Savedinstancestate) {<span class="hljs-keyword">super </span>. onCreate (savedinstancestate); Activitycollector.addactivity (<span class="hljs-keyword">this </span>); } <span class="hljs-annotation"> @Override </span> <span class="hljs-keyword">protected </span> <span class=" Hljs-keyword ">void </span> <span class=" hljs-title ">ondestroy </span> () {<span class=" hljs-keyword ">super </span>. OnDestroy (); Activitycollector.removeactivity (<span class="hljs-keyword">this </span>); }}</code></code></pre><p><p><strong>Loginactivity.java</strong></p></p><pre class="prettyprint"><code class="language-Java hljs java"><span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-class"><span class="hljs-class"> <span class="hljs-keyword">class</span> <span class="hljs-title">loginactivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">baseactivity</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">View</span>. <span class="hljs-title">Onclicklistener</span> {</span></span> <span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>Sharedpreferences pref;<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>Sharedpreferences.editor Editor;<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>EditText edit_user;<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>EditText edit_pawd;<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>Button btn_login;<span class="hljs-annotation"><span class="hljs-annotation">@Override</span></span> <span class="hljs-keyword"><span class="hljs-keyword">protected</span></span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">onCreate</span></span>(Bundle Savedinstancestate) {<span class="hljs-keyword"><span class="hljs-keyword">Super</span></span>. onCreate (savedinstancestate); Setcontentview (r.layout.activity_login); Pref = Preferencemanager.getdefaultsharedpreferences (<span class="hljs-keyword"><span class="hljs-keyword"></span> this</span>); Bindviews (); }<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">bindviews</span></span>() {edit_user = (EditText) Findviewbyid (r.id.edit_user); Edit_pawd = (EditText) Findviewbyid (r.id.edit_pawd); Btn_login = (Button) Findviewbyid (r.id.btn_login); Btn_login.setonclicklistener (<span class="hljs-keyword"><span class="hljs-keyword"></span> this</span>); }<span class="hljs-annotation"><span class="hljs-annotation">@Override</span></span> <span class="hljs-keyword"><span class="hljs-keyword">protected</span></span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">OnStart</span></span>() {<span class="hljs-keyword"><span class="hljs-keyword">Super</span></span>. OnStart ();<span class="hljs-keyword"><span class="hljs-keyword">if</span></span>(!pref.getstring (<span class="hljs-string"><span class="hljs-string">"user"</span></span>,<span class="hljs-string"><span class="hljs-string">""</span></span>). Equals (<span class="hljs-string"><span class="hljs-string">""</span></span>) {edit_user.settext (pref.getstring (<span class="hljs-string"><span class="hljs-string">"user"</span></span>,<span class="hljs-string"><span class="hljs-string">""</span></span>)); Edit_pawd.settext (pref.getstring (<span class="hljs-string"><span class="hljs-string">"pawd"</span></span>,<span class="hljs-string"><span class="hljs-string">""</span></span>)); } }<span class="hljs-annotation"><span class="hljs-annotation">@Override</span></span> <span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">OnClick</span></span>(View V) {String user = Edit_user.gettext (). toString (); String pawd = edit_pawd.gettext (). toString ();<span class="hljs-keyword"><span class="hljs-keyword">if</span></span>(user.equals (<span class="hljs-string"><span class="hljs-string">"123"</span></span>) &&pawd.equals (<span class="hljs-string"><span class="hljs-string">"123"</span></span>) {editor = Pref.edit (); Editor.putstring (<span class="hljs-string"><span class="hljs-string">"user"</span></span>, user); Editor.putstring (<span class="hljs-string"><span class="hljs-string">"pawd"</span></span>, pawd); Editor.commit (); Intent Intent =<span class="hljs-keyword"><span class="hljs-keyword">New</span></span>Intent (loginactivity.<span class="hljs-keyword"><span class="hljs-keyword"></span> this</span>, mainactivity.class); StartActivity (intent); Toast.maketext (loginactivity.<span class="hljs-keyword"><span class="hljs-keyword"></span> this</span>,<span class="hljs-string"><span class="hljs-string">"yo, That's right!"</span></span>, toast.length_short). show (); Finish (); }<span class="hljs-keyword"><span class="hljs-keyword">Else</span></span>{toast.maketext (loginactivity).<span class="hljs-keyword"><span class="hljs-keyword"></span> this</span>,<span class="hljs-string"><span class="hljs-string">"so Simple is the output, what about the brain?" "</span></span>, toast.length_short). show (); } }}</code></pre><p><p><strong>Step 3</strong>: Customize a broadcastreceiver, complete the popup dialog in onreceive, and launch the landing page:<br><strong>Mybcreceiver.java</strong></p></p><pre class="prettyprint"><code class="language-Java hljs java"><span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-class"><span class="hljs-class"> <span class="hljs-keyword">class</span> <span class="hljs-title">mybcreceiver</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">broadcastreceiver</span> {</span></span> <span class="hljs-annotation"><span class="hljs-annotation">@Override</span></span> <span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">OnReceive</span></span>(<span class="hljs-keyword"><span class="hljs-keyword">Final</span></span>Context context, Intent Intent) {alertdialog.builder dialogbuilder =<span class="hljs-keyword"><span class="hljs-keyword">New</span></span>Alertdialog.builder (context); Dialogbuilder.settitle (<span class="hljs-string"><span class="hljs-string">"warning:"</span></span>); Dialogbuilder.setmessage (<span class="hljs-string"><span class="hljs-string">"your account is logged in elsewhere, please re-login ~"</span></span>); Dialogbuilder.setcancelable (<span class="hljs-keyword"><span class="hljs-keyword">false</span></span>); Dialogbuilder.setpositivebutton (<span class="hljs-string"><span class="hljs-string">"ok"</span></span>,<span class="hljs-keyword"><span class="hljs-keyword">New</span></span>Dialoginterface.onclicklistener () {<span class="hljs-annotation"><span class="hljs-annotation">@Override</span></span> <span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">OnClick</span></span>(dialoginterface dialog,<span class="hljs-keyword"><span class="hljs-keyword">int</span></span>Which) {activitycollector.finishall (); Intent Intent =<span class="hljs-keyword"><span class="hljs-keyword">New</span></span>Intent (context, loginactivity.class); Intent.addflags (intent.flag_activity_new_task); Context.startactivity (intent); } }); Alertdialog Alertdialog = dialogbuilder.create (); Alertdialog.getwindow (). SetType (WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); Alertdialog.show (); }}</code></pre><p><p>Don't forget to add the System dialog box to the Androidmanifest.xml:<br><strong>< uses-permission android:name= "android.permission.SYSTEM_ALERT_WINDOW"/></strong></p></p><p><p><strong>Step 4:</strong> in the mainactivity, instantiate the localbroadcastmanager, take him to complete the relevant operation, in addition to destroy<br>Note unregisterreceiver!</p></p><p><p><strong>Mainactivity.java</strong></p></p><pre class="prettyprint"><code class="language-Java hljs java"><span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-class"><span class="hljs-class"> <span class="hljs-keyword">class</span> <span class="hljs-title">mainactivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">baseactivity</span> {</span></span> <span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>Mybcreceiver localreceiver;<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>Localbroadcastmanager localbroadcastmanager;<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>Intentfilter intentfilter;<span class="hljs-annotation"><span class="hljs-annotation">@Override</span></span> <span class="hljs-keyword"><span class="hljs-keyword">protected</span></span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">onCreate</span></span>(Bundle Savedinstancestate) {<span class="hljs-keyword"><span class="hljs-keyword">Super</span></span>. onCreate (savedinstancestate); Setcontentview (r.layout.activity_main); Localbroadcastmanager = Localbroadcastmanager.getinstance (<span class="hljs-keyword"><span class="hljs-keyword"></span> this</span>);<span class="hljs-comment"><span class="hljs-comment">//initialize the broadcast receiver, set the filter</span></span>Localreceiver =<span class="hljs-keyword"><span class="hljs-keyword">New</span></span>Mybcreceiver (); Intentfilter =<span class="hljs-keyword"><span class="hljs-keyword">New</span></span>Intentfilter (); Intentfilter.addaction (<span class="hljs-string"><span class="hljs-string">"com.jay.mybcreceiver.LOGIN_OTHER"</span></span>); Localbroadcastmanager.registerreceiver (localreceiver, intentfilter); Button Btn_send = (button) Findviewbyid (r.id.btn_send); Btn_send.setonclicklistener (<span class="hljs-keyword"><span class="hljs-keyword">New</span></span>View.onclicklistener () {<span class="hljs-annotation"><span class="hljs-annotation">@Override</span></span> <span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">OnClick</span></span>(View V) {Intent Intent =<span class="hljs-keyword"><span class="hljs-keyword">New</span></span>Intent (<span class="hljs-string"><span class="hljs-string">"com.jay.mybcreceiver.LOGIN_OTHER"</span></span>); Localbroadcastmanager.sendbroadcast (intent); } }); }<span class="hljs-annotation"><span class="hljs-annotation">@Override</span></span> <span class="hljs-keyword"><span class="hljs-keyword">protected</span></span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">OnDestroy</span></span>() {<span class="hljs-keyword"><span class="hljs-keyword">Super</span></span>. OnDestroy (); Localbroadcastmanager.unregisterreceiver (localreceiver); }}</code></pre><p><p>ok, so simple, don't forget to register for activity Oh ~</p></p>2.Android 4.3 or above monitoring boot start broadcast problem resolution:<p><p>on Android 4.3 or above, allows us to install the application on the sd, we all know is the system boot<br>After a short interval of time, the SD card is loaded, so our application may not be able to listen to this broadcast!<br>So we need both to monitor the boot broadcast and monitor the SD card Mount broadcast!<br>In addition, some phones may not have an SD card, so these two radio listeners we can't write to the same intetn-filter.<br>instead, It should be written in two, with the following configuration code:</p></p><pre class="prettyprint"><code class="language-Java hljs xml"><span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">receiver</span> <span class="hljs-attribute">android:name</span>=<span class="hljs-value">". Mybroadcastreceiver "</span>></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">intent-filter</span>></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">action</span> <span class="hljs-attribute">android:name</span>=<span class="hljs-value">"android.intent.action.BOOT_COMPLETED"</span>/></span></span> <span class="hljs-tag"><span class="hljs-tag"></<span class="hljs-title">intent-filter</span>></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">intent-filter</span>></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">action</span> <span class="hljs-attribute">android:name</span>=<span class="hljs-value">"android. INTENT. ACTION. media_mounted "</span>/></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">action</span> <span class="hljs-attribute">android:name</span>=<span class="hljs-value">"android. INTENT. ACTION. media_unmounted "</span>/></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">data</span> <span class="hljs-attribute">android:scheme</span>=<span class="hljs-value">"file"</span>/></span></span> <span class="hljs-tag"><span class="hljs-tag"></<span class="hljs-title">intent-filter</span>></span></span><span class="hljs-tag"><span class="hljs-tag"></<span class="hljs-title">receiver</span>></span></span></code></pre>3. Common system Broadcast summary:<p><p>finally, we will provide you with some of the systems we may normally use to broadcast it:</p></p><pre class="prettyprint"><code class="language-XML hljs cs">intent.action_airplane_mode_changed;<span class="hljs-comment"><span class="hljs-comment">//broadcast When airplane mode is turned off or on</span></span>intent.action_battery_changed;<span class="hljs-comment"><span class="hljs-comment">//charge status, or the battery charge is changed</span></span><span class="hljs-comment"><span class="hljs-comment">//battery charge status, charge level change, cannot receive this broadcast through the build statement, only through Context.registerreceiver () registration</span></span>intent.action_battery_low;<span class="hljs-comment"><span class="hljs-comment">//indicates Low battery power</span></span>intent.action_battery_okay;<span class="hljs-comment"><span class="hljs-comment">//indicates that the battery is fully charged, i.e. the broadcast will be issued when the battery level changes from low to full</span></span>intent.action_boot_completed;<span class="hljs-comment"><span class="hljs-comment">//after The system boot is complete, This action is broadcast once (only once). </span></span>intent.action_camera_button;<span class="hljs-comment"><span class="hljs-comment">//press the camera button (hardware Button) to broadcast</span></span>intent.action_close_system_dialogs;<span class="hljs-comment"><span class="hljs-comment">//when the screen times out for the lock screen, the Android system broadcasts the action message when the user presses the power button, long Press or short press (whether or not to jump out of the box).</span></span>intent.action_configuration_changed;<span class="hljs-comment"><span class="hljs-comment">//the broadcast (including changes: interface language, device orientation, Etc.) issued when the Device's current settings are changed, please refer to Configuration.java</span></span>intent.action_date_changed;<span class="hljs-comment"><span class="hljs-comment">This broadcast will be issued when the device date has changed</span></span>intent.action_device_storage_low;<span class="hljs-comment"><span class="hljs-comment">//when The device is out of memory, this broadcast can only be used by the system and other apps are not available? </span></span>intent.action_device_storage_ok;<span class="hljs-comment"><span class="hljs-comment">//device memory from insufficient to sufficient when the broadcast, this broadcast can only be used by the system, other apps are not available? </span></span>intent.action_dock_event;<span class="hljs-comment"><span class="hljs-comment">//</span></span><span class="hljs-comment"><span class="hljs-comment">//where This broadcast was issued Frameworks\base\services\java\com\android\server\dockobserver.java</span></span>intent.action_external_applications_available;<span class="hljs-comment"><span class="hljs-comment"> <span class="hljs-xmlDocTag"></span>////after The mobile app is complete, the broadcast (mobile means: App2sd)</span></span>intent.action_external_applications_unavailable;<span class="hljs-comment"><span class="hljs-comment">//when The app is being moved, the broadcast (mobile means: App2sd)</span></span>intent.action_gtalk_service_connected;<span class="hljs-comment"><span class="hljs-comment">//gtalk Broadcast When a connection has been established</span></span>intent.action_gtalk_service_disconnected;<span class="hljs-comment"><span class="hljs-comment">//gtalk Broadcast When a connection has been disconnected</span></span>intent.action_headset_plug;<span class="hljs-comment"><span class="hljs-comment">//broadcast When the headset is plugged into the headphone port</span></span>intent.action_input_method_changed;<span class="hljs-comment"><span class="hljs-comment">//change the Input method when the broadcast is issued</span></span>intent.action_locale_changed;<span class="hljs-comment"><span class="hljs-comment">radio emitted when the Device's current locale has changed</span></span>intent.action_manage_package_storage;<span class="hljs-comment"><span class="hljs-comment">//</span></span>intent.action_media_bad_removal;<span class="hljs-comment"><span class="hljs-comment">//incorrect Removal of SD card (method to correctly remove SD card: SET--SD card and device Memory--uninstall SD card), but broadcast when the SD card</span> is removed</span><span class="hljs-comment"><span class="hljs-comment">//broadcast: Extended Media (expansion Card) has been unplugged from SD card slot, But mount point has not been lifted (unmount)</span></span>intent.action_media_button;<span class="hljs-comment"><span class="hljs-comment">//press the "media button" button to broadcast, if there is a "media button" button (hardware Button)</span></span>intent.action_media_checking;<span class="hljs-comment"><span class="hljs-comment">//when inserting an external storage device, such as an SD card, the system will verify the SD card and broadcast it at this time?</span></span>intent.action_media_eject;<span class="hljs-comment"><span class="hljs-comment">//unplugged a broadcast from an external mass storage device (such as an SD card, or a removable hard drive), This broadcast will be issued whether or not the uninstallation is correct?</span></span><span class="hljs-comment"><span class="hljs-comment">//broadcast: The user wants to remove the extended media (unplug the expansion card). </span></span>intent.action_media_mounted;<span class="hljs-comment"><span class="hljs-comment">//the broadcast that was issued when the SD card was inserted and properly installed (recognized)</span></span><span class="hljs-comment"><span class="hljs-comment">//broadcast: The extended media is plugged in and is already mounted. </span></span>intent.action_media_nofs;<span class="hljs-comment"><span class="hljs-comment">//</span></span>intent.action_media_removed;<span class="hljs-comment"><span class="hljs-comment">//external storage Device has been removed, This broadcast will be issued, whether or not it is uninstalled properly? </span></span><span class="hljs-comment"><span class="hljs-comment">//broadcast: The extended media is Removed. </span></span>intent.action_media_scanner_finished;<span class="hljs-comment"><span class="hljs-comment">//broadcast: A directory that has been scanned for media</span></span>intent.action_media_scanner_scan_file;<span class="hljs-comment"><span class="hljs-comment">//</span></span>intent.action_media_scanner_started;<span class="hljs-comment"><span class="hljs-comment">//broadcast: Start scanning a directory of media</span></span>intent.action_media_shared;<span class="hljs-comment"><span class="hljs-comment">//broadcast: The Mount of the extended media is lifted (unmount) because it has been shared as a USB mass storage. </span></span>intent.action_media_unmountable;<span class="hljs-comment"><span class="hljs-comment">//</span></span>intent.action_media_unmounted<span class="hljs-comment"><span class="hljs-comment">//broadcast: the extended media exists, but is not mounted (mount). </span></span>Intent.action_new_outgoing_call;intent. action_package_added;<span class="hljs-comment"><span class="hljs-comment">//successful Installation apk</span></span><span class="hljs-comment"><span class="hljs-comment">//broadcast: A new application package is installed on the Device. </span></span><span class="hljs-comment"><span class="hljs-comment">//a new app package is already installed on the device, the data includes the package name (the latest Installed package program cannot receive this broadcast)</span></span>intent.action_package_changed;<span class="hljs-comment"><span class="hljs-comment">//an Existing application package has changed, including the package name</span></span>intent.action_package_data_cleared;<span class="hljs-comment"><span class="hljs-comment">//clear the broadcast of an Application's data (in settings--app management--select an app, then point to clear data?)</span></span><span class="hljs-comment"><span class="hljs-comment">//the user has cleared the data for a package, including the package name (the Purge Package program cannot receive this broadcast)</span></span>intent.action_package_install;<span class="hljs-comment"><span class="hljs-comment">//trigger a download and complete the broadcast of the installation, such as downloading the app in the electronics market? </span></span><span class="hljs-comment"><span class="hljs-comment">//</span></span>intent.action_package_removed;<span class="hljs-comment"><span class="hljs-comment">//successful deletion of an APK after the broadcast issued</span></span><span class="hljs-comment"><span class="hljs-comment">//an Existing application package has been removed from the device, including the package name (the package program being installed cannot receive this broadcast)</span></span>intent.action_package_replaced;<span class="hljs-comment"><span class="hljs-comment">//replace A broadcast that is issued when an existing installation package (whether The app is now installed than the new or old one, will issue this broadcast?). )</span></span>intent.action_package_restarted;<span class="hljs-comment"><span class="hljs-comment">//the User restarts a package, all processes of the package will be killed, all runtime status associated with it should be removed, including the package name (restart Package program cannot receive this broadcast)</span></span>intent.action_power_connected;<span class="hljs-comment"><span class="hljs-comment">//broadcast When external power is plugged</span> in</span>intent.action_power_disconnected;<span class="hljs-comment"><span class="hljs-comment">//broadcast sent when external power is disconnected</span></span>intent.action_provider_changed;<span class="hljs-comment"><span class="hljs-comment">//</span></span>intent.action_reboot;<span class="hljs-comment"><span class="hljs-comment">//broadcast When restarting the device</span></span>intent.action_screen_off;<span class="hljs-comment"><span class="hljs-comment">//screen is closed after the broadcast</span></span>intent.action_screen_on;<span class="hljs-comment"><span class="hljs-comment">//broadcast After the screen is opened</span></span>intent.action_shutdown;<span class="hljs-comment"><span class="hljs-comment">//broadcast When shutting down the system</span></span>intent.action_timezone_changed;<span class="hljs-comment"><span class="hljs-comment">//the broadcast that is issued when the time zone has changed</span></span>intent.action_time_changed;<span class="hljs-comment"><span class="hljs-comment">//time is set when the broadcast is issued</span></span>intent.action_time_tick;<span class="hljs-comment"><span class="hljs-comment">//broadcast: The current time has changed (normal time passes). </span></span><span class="hljs-comment"><span class="hljs-comment">//current time changes, sent every minute, cannot be received through component declaration, only registered by Context.registerreceiver () method</span></span>intent.action_uid_removed;<span class="hljs-comment"><span class="hljs-comment">//a User ID has been removed from the system for the broadcast sent</span></span><span class="hljs-comment"><span class="hljs-comment">//</span></span>intent.action_ums_connected;<span class="hljs-comment"><span class="hljs-comment">//when The device has entered the USB mass storage state when the broadcast is issued? </span></span>intent.action_ums_disconnected;<span class="hljs-comment"><span class="hljs-comment">//the broadcast when the device has been converted from a USB mass storage state to a normal state? </span></span>intent.action_user_present;<span class="hljs-comment"><span class="hljs-comment">//</span></span>intent.action_wallpaper_changed;<span class="hljs-comment"><span class="hljs-comment">//the broadcast when the device wallpaper has changed</span></span></code></pre>4. Summary of this section:<p><p>ok, about Broadcastreceiver's Study is here, if you have any supplementary or suggestion, Welcome to ask ~<br>Extremely grateful</p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Android Basics Getting Started tutorial--4.3.2 broadcastreceiver discovering</p></p></span>
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