Frank Harper
Frank Harper

Reputation: 3176

Can't use @string notation to define <intent-filter> in AndroidManifest.xml

My BroadcastReceiver never gets called when I use "@string/action_name" to define the intent filter action. If I copy/paste the corresponding string from strings.xml into AndroidManifest.xml, then it works perfectly!

Non working example from AndroidManifest.xml:

<receiver
    android:name=".ServerUpdateReceiver" >
    <intent-filter>
        <action android:name="@string/ACTION_INFORM_USER_SERVER_UPDATE" />
    </intent-filter>
</receiver>

Working example from AndroidManifest.xml:

    <receiver
        android:name=".ServerUpdateReceiver" >
        <intent-filter>
            <action android:name="com.franklinharper.intent.action.ACTION_INFORM_USER_SERVER_UPDATE" />
        </intent-filter>
    </receiver>

Just for completeness, strings.xml contains the following line:

<string name="ACTION_INFORM_USER_SERVER_UPDATE">com.franklinharper.intent.action.ACTION_INFORM_USER_SERVER_UPDATE</string>

Upvotes: 19

Views: 3187

Answers (1)

Femi
Femi

Reputation: 64700

From the spec, there is no way to configure an action with a resource identifier. It has to be a simple string, perhaps to avoid requiring the Android Intent dispatch system to open your APK to figure out what the filter is for.

Upvotes: 29

Related Questions