2
votes

I have a broadcast receiver with an intent filter that specifies a single custom category:

    <receiver
        android:name=".sys.sub.SubServiceManager"
        android:enabled="true"
        android:exported="false" >
        <intent-filter>
            <category android:name="com.example.SUB_SERVICE_STATE" />
        </intent-filter>
    </receiver>

Then there is this code that issues a broadcast using that intent category with custom actions. My problem is the broadcast is never received.

    Intent speed = new Intent();
    speed.addCategory(inst.getString(R.string.subServiceCat));
    speed.setAction("com.example." + SubServiceManager.START_COMMAND + Example.NAME);
    inst.sendBroadcast(speed);

R.string.subServiceCat holds the same string as defined in the intent-filter.

Is there something else I have to do for a custom-category intent filter?

1

1 Answers

3
votes

Documentation says:

To pass this test(Action test ), the action specified in the Intent object must match one of the actions listed in the filter. If the object(intent) or the filter does not specify an action, the results are as follows:

  • If the filter fails to list any actions, there is nothing for an intent to match, so all intents fail the test. No intents can get through the filter.
  • On the other hand, an Intent object that doesn't specify an action automatically passes the test — as long as the filter contains at least one action.

You see that your filter does not specify an action,so your intent can not get through the filter.To solve this problem you would to specify an action to your receiver's filter or do not specify any action to your intent.