Search code examples
androidxmlbroadcastreceiverandroid-manifestintentfilter

Use app name in intent filter action name


I'm trying to create a BroadcastReveiver with couple of intent filters in AndroidManifest.xml. I need to use app name as a part of action name. For example:

<receiver android:name=".SomeBroadcastReceiver">
    <intent-filter>
        <action android:name="<app_name>.SOME_ACTION" />
    </intent-filter>
</receiver>

I'm pretty sure it's not possible to do this but I hope there is some another way to do something like this?

I can register receiver in Application class but then it won't keep listening when app process is not not active. Is there any way to listen these actions as long as app is installed?


Solution

  • Assuming that "app name" is what Android developers refer to as the application ID (or the older "package name" term), use manifest placeholders:

    <action android:name="${applicationId}.SOME_ACTION" />