I have an application that runs as a service in the background. I want another third-party application to be able to call multiple functionalities on this app via an intent. How would I achieve this. Presently the only thing i know how to do with intent is launching other applications and starting activities.
Asked
Active
Viewed 38 times
-1
-
1Search for inter process communication or inter application communication in android. – Bek Jul 29 '19 at 11:02
1 Answers
2
This can be achieved with a BroadcastReceiver.
Create a class that extends BroadcastReceiver and implements it's onReceive() method to handle intent appropriately:
@Override public void onReceive(Context context, Intent intent) {
if (ACTION.equals(intent.getAction())) {
// Do something..
}
}
This receiver must be declared in the manifest of the app and be exported and enabled like below:
<receiver android:name=".BroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="ACTION" />
</intent-filter>
</receiver>
You will need to send your intent from the first app as a broadcast:
sendBroadcast(intent);

JakeB
- 2,043
- 3
- 12
- 19
-
1take into consideration that implicit broadcasts will not work in Android Oreo+, check this answer https://stackoverflow.com/a/49197540/6248510 – fmaccaroni Jul 29 '19 at 11:39