Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 919
Frank Harper Avatar asked Apr 17 '12 06:04

Frank Harper


1 Answers

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.

like image 117
Femi Avatar answered Oct 18 '22 14:10

Femi