How to use Broadcast Receiver in different Applications in Android?

后端 未结 4 2060
日久生厌
日久生厌 2020-11-29 09:04

I have here two applications in two different projects in eclipse. One application (A) defines an activity (A1) which is started first. Then i start from this activity the s

相关标签:
4条回答
  • 2020-11-29 09:26

    what ever action we are passing inside in android, we have to use same action while creating Intent object or setAction() method of Intent. when we will send this Intent object with the help of sendBroadcasteReceiver() method of Context then it will send this action to all receiver(without permission), what ever receiver we have set in Manifest.xml all will(who has same action in intent-filter tag) get this action.

    0 讨论(0)
  • 2020-11-29 09:27

    Still not working for you?

    Though the answers are helpful I still had the a problem. I got the solution here.

    when sending the broadcast add the ff flag:

    FLAG_INCLUDE_STOPPED_PACKAGES flag is added to the intent before it is sent to indicate that the intent is to be allowed to start a component of a stopped application.

    intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    
    0 讨论(0)
  • 2020-11-29 09:39
    1. Your <receiver> element needs to be a peer of your <activity> element, not a child.
    2. Your action string should NOT be in the android.intent.action namespace, unless you work for Google -- use ch.ifi.csg.games4blue.games.pacman.controller.BROADCAST or something like that instead
    3. Your <intent-filter> with your custom action needs to be placed on the <receiver>, not the sending or receiving <activity>

    See here for an example of implementing a manifest-registered broadcast receiver (for a system-broadcast Intent).

    0 讨论(0)
  • 2020-11-29 09:39

    Intent intent = new Intent("pacman.intent.action.BROADCAST");

    vs.

    <android:name="android.intent.action.BROADCAST"/>

    Are you sure you use the same string in real code?

    0 讨论(0)
提交回复
热议问题