I have been able to get my BroadcastReceiver running with this:
<receiver
android:name=".AlarmReceiver"
android:enabled="true"
android:exported="false">
</receiver>
As you can see no <intent-filter>. It gets called correctly with the right Intent extras. But I have been looking around and I am confused as to whether I need one or not? I do have a setAction() method called on my Intents but to make them unique from others to ensure a specific issue with notifications, not actually using that action’s string. But what exactly is the correlation? Thanks in advance.
Intent intent = new Intent(this.getContext(), AlarmReceiver.class);
intent.setAction("com.something"+System.currentTimeMillis());
//... extras are here
PendingIntent pi = PendingIntent.getBroadcast(this.getContext(), 123, intent, PendingIntent.FLAG_CANCEL_CURRENT|Intent.FILL_IN_DATA);
AlarmManager alarm = (AlarmManager)getContext().getSystemService(Activity.ALARM_SERVICE);
alarm.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), pi);
Using that with what I have in the manifest file works.
EDIT
I found this on the Android Developers blog, and it states this:
Implicit Intents only specify “what” they should match, using actions, categories, data,
MIME types, and so on. The exact components that they will find are only determined at
run-time, by the Package Manager matching it against the current applications.
Explicit Intents specify a single explicit “who” they should match, through a
ComponentName. Regardless of whatever else is in the Intent, it is only associated with
the exact manifest package name and class name as given in its ComponentName.
I am still slightly confused with this explanation, but it seems to be the closest thing to what I should be doing. So I am sure I am using an implicit intent. Question is, is it ok that I am leaving out <intent-filter>? I am matching it to a specific class. There may not be an actual action tying them together, perse, but is the class enough?
<intent-filter>is required when you want to start your receiver using implicit intents, if you are always using explicit intents to start your broadcast receiver then intent-filters are not required.see this SO Post.