Intent Broadcast Receiver

I have two applications that I completely manage. Both sign with the same certificate, and both use the same intent filter. One sends the broadcast from the fragment, and the other sends it in and does something. However, this does not work:

Strings.FILTER_INIT_REGISTER = "com.app.FILTER_INIT_REGISTER" Intent intent = new Intent(Strings.FILTER_INIT_REGISTER); getActivity().sendBroadcast(intent); 

I registered the receiver in the Manifest application tag for the application containing the ReportingReceiver class:

 <receiver android:name=".receivers.ReportingReceiver" android:exported="true" > <intent-filter> <action android:name="com.app.FILTER_INIT_REGISTER" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </receiver> 

Curious why the ReportingReceiver class does not receive an intent call?

+4
source share
2 answers

If your application has only a service and receivers, this will not work in Android 3.1 and later. The reason is that the system will not send broadcast intentions to an application located in STOPPED STATE . The application is in STOPPED STATE when it is first installed. It is removed from STOPPED STATE when the user manually launches the application for the first time. It returns to STOPPED STATE if the user forces the application to stop using the application manager tool.

Since your application has no actions, the user has no way to "launch" it. Therefore, he will never get out of a stop state.

See http://developer.android.com/about/versions/android-3.1.html#launchcontrols

+14
source

As Android Addict claims in a comment on David Wasser, there is a way around this behavior.

Just add the following flag to the calling Intent. This ensures that you also receive broadcast receivers from β€œstopped” applications.

http://developer.android.com/reference/android/content/Intent.html#FLAG_INCLUDE_STOPPED_PACKAGES

You can read more about this Android 3.1 here.

http://developer.android.com/about/versions/android-3.1.html#launchcontrols

and here

http://code.google.com/p/android/issues/detail?id=18225

+7
source

Source: https://habr.com/ru/post/1438453/


All Articles