Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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

not working..

Edits :

<receiver android:name="com.sample.ThemesUpdatedReceiver">
        <intent-filter>
            <action android:name="com.sample.THEMES_UPDATED"/>
        </intent-filter>
    </receiver>
like image 394
AJit Avatar asked Oct 10 '13 19:10

AJit


3 Answers

@Ajit: Hi, Since Android API 3.0 [API level 11], If an application has never been started even once, then it's BroadcastReceiver can't receive events.As, in your case, your app has no launcher activity, so may be it is the case that causes rejection of event.

Along with that please try using below approach: You have passed that constant value while creating Intent object. Instead pass it in method intent.setAction();

Hope this helps.

like image 85
Anish Mittal Avatar answered Sep 28 '22 08:09

Anish Mittal


I figured that every sent broadcast is received by all applications except when you setPackage to the sending intent for specific package broadcast.

I am not receiving broadcast because my another app is not launched(that doesn't have launcher activity).

like image 36
AJit Avatar answered Sep 28 '22 09:09

AJit


If you're going to broadcast, it generally follows you have a sender and receiver. You've posted what looks like the sender ..

sender (where ever you're sending from):

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

receiver (in eg 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);

Sender always sends, receiver needs to register to listen for the intent.

like image 39
K5 User Avatar answered Sep 28 '22 08:09

K5 User