Send broadcast from one apk / package to another apk / package

I need to send the broadcast from my one application to another application .. any help! my application package: 1) com.demo.database and 2) com.demo.list

Intent themesIntent = new Intent(ThemesManager.THEMES_UPDATED); themesIntent.putExtra("package", packageName); ctx.sendBroadcast(themesIntent); 

does not work.

Editing:

 <receiver android:name="com.sample.ThemesUpdatedReceiver"> <intent-filter> <action android:name="com.sample.THEMES_UPDATED"/> </intent-filter> </receiver> 
+6
source share
3 answers

@Ajit: Hi, Since Android API 3.0 [API level 11], if the application has never been run once, then BroadcastReceiver cannot receive events. Since in your case your application does not have launch activity, it may happen that this causes an event to be rejected.

Along with this, try the approach below: You passed this constant value when creating the Intent object. Instead, pass it in the intent.setAction () method;

Hope this helps.

+5
source

If you intend to broadcast, it usually follows that you have a sender and a recipient. You sent what looks like a sender.

sender (where do you send):

 Intent toret = new Intent(); toret.setAction("com.myapp.foo"); toret.putExtra("bar", "fizzbuzz"); sendBroadcast(toret); 

(e.g. onResume() )

  IntentFilter intentFilter = new IntentFilter("com.myapp.foo"); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // ... do something with the intent } // register the receiver this.registerReceiver(receiver , intentFilter); 

The sender always sends, the receiver must register to listen to the intent.

+2
source

I realized that every broadcast sent is accepted by all applications, unless you set Package to send intent for a specific packet transfer.

I do not receive the broadcast because my other application does not start (this has no start activity).

+2
source

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


All Articles