Possible causes for Android not receiving broadcasts

Source: Internet
Author: User

1. Android 4.0 in order to prevent some malware (malware) run in the background without user startup, the default installation of the program is completely ignored by the system before the user starts, even if the program registered the broadcast, the system will not pass the broadcast to the program. The message broadcast will not take effect until the program has been run by the user. Moreover, even if the program is already running, if the user forces stop (force stopped), it will return to the state ignored by the system.

In this case, a third-party app can receive broadcasts only in a running state (including activity in the background), and system applications are accepted under any circumstances.

2. The broadcast specifies the datatype, which is not specified in our registered Intent-filter.

By intent-filter the implicit start of a activity,service, the intent-filter of the recessive component must be written as follows:

"I am the component xxxx, I want to receive such an implicit event: its action must be XXX, its category must be YYYY, it contains the data must be zzzz"

If the component does not declare intentfilter, then all implicit events are not sent to the component. (Note that this does not affect sending an explicit event to the component.) )

This is why the simplest covert activation activity is intent-filter as follows:

<intent-filter><action android:name= "Com.android.action.NNN"/><category android:name= " Android.intent.category.DEFAULT "/></intent-filter>

Because the default intent has a default category value in addition to action.

When a photo is taken, the camera sends the following broadcast:

public static void Broadcastnewpicture (context context, Uri Uri) {context.sendbroadcast (new Intent (Action_new_picture, URI)); Context.sendbroadcast (New Intent ("Com.android.camera.NEW_PICTURE", Uri));}

To receive a broadcast you must write as follows:

<receiver android:name= "Com.android.gallery3d.vivo.NewPictureBroadcastReceiver" ><intent-filter>< Action android:name= "Android.hardware.action.NEW_PICTURE"/><data android:mimetype= "image/*"/></ Intent-filter><intent-filter><action android:name= "Com.android.camera.NEW_PICTURE"/><data Android:mimetype= "image/*"/></intent-filter>            </receiver>    

Reference: Add adddatascheme ("file") to receive the cause analysis of SD card Plug and Unplug event--an analysis of the Android event filtering strategy

Possible causes for Android not receiving broadcasts

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.