I'm programming an application that will fire a specific method once it hits a certain date / time. However, my broadcast reciever is not firing...i can see that the alarm is set.
my method within an activity:
private void setAlarm(Date date){
Intent activate = new Intent(this, Alarm.class);
AlarmManager alarms ;
Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(date.getTime());
PendingIntent alarmIntent = PendingIntent.getBroadcast(this, 0, activate, 0);
alarms = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
Log.d("ALARM","Setting alarm");
alarms.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), alarmIntent);
Log.d("ALARM","Setting time "+cal.getTimeInMillis());
}
My BroadcastReciever:
public class Alarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("ALARM", "RING RING");
}
}
My manifest within the <application>
tag:
<receiver android:name=".Alarm" android:process=":remote" >
<intent-filter>
<action android:name="com.package.feature.subpackage.arrangealarm.ALARM_ACTION"/>
</intent-filter>
</receiver>
Does anyone have any idea why this is not firing?
There seems to be nothing wrong with your code (I copied the snippet and had Android Studio generate a BroadcastReceiver for which I set android:process=":remote"
just like you do).
When I run the app, the BroadcastReceiver
fires but I can only see the respective Logcat entry when I select "No Filters" in the Logcat settings (on the right side), not when I choose "Show only selected application".
This happens because you use android:process=":remote"
. The BroadcastReceiver will run in another process than the "main" application process, so the "RING RING" will appear under another process id.