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

Exception or error:

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>
How to solve:

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.

Leave a Reply

Your email address will not be published. Required fields are marked *