0

I created an Application that shares a BroadcastReceiver that launches a Service.

The app that holds the receiver doesn't have activities, there are the receiver class and the services.

Here are the manifest declaration:

        <service
            android:name=".services.PrintService"
            android:enabled="true"
            android:exported="true" />

        <receiver
            android:name=".receivers.MyReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="art.bridge.PRINT_MESSAGE" />
            </intent-filter>
        </receiver>

Receiver class

public class MyReceiver extends BroadcastReceiver {
    public MyReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(ArtAppl.name , "Receiver reached");
        Intent print = new Intent(context, PrintService.class);
        if(intent.getStringExtra("message") != null)
            print.putExtra("message",intent.getStringExtra("message"));
        else
            print.putExtra("message","Message not found");

        context.startService(print);
    }
}

Form an another app, i try to launch the receiver like following:

        Intent bReceiver = new Intent("art.bridge.PRINT_MESSAGE");
        sendBroadcast(bReceiver);

But the receiver doesn't run.

Am I missing something? Do I have to set another action in the manifest?

MikeKeepsOnShine
  • 1,730
  • 4
  • 23
  • 35

1 Answers1

0

Could it be that you need to include Intent.FLAG_INCLUDE_STOPPED_PACKAGES as a flag?

See: How to Send BroadCast from one app to another app

Community
  • 1
  • 1
Michael Dodd
  • 10,102
  • 12
  • 51
  • 64