This question has been asked multiple times. But most of the answers provided are either not working, or a solution specific only to a certain situation. Well I am having difficulty esp on testing my app. I have a code which sets off the alarm like this:
public void setAlarm(Context context)
{
if((mNote == null) && (!mNote.getRemindEnabled() || mNote.getRemindOnDate() == null))
return;
Intent alarmIntent = new Intent(context, NoteAlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);
Calendar calendar = mNote.getRemindCalendar();
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
manager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIntent);
Toast.makeText(context, "NoteAlarm.setAlarm() : Note " + mNote.getShortNote() + " has been set" , Toast.LENGTH_LONG).show();
Log.i(NoteApplication.TAG, "NoteAlarm.setAlarm() : Note " + mNote.getShortNote() + " has been set");
}
AlarmReceiver class receives the said alarm using this code:
@Override
public void onReceive(Context context, Intent intent)
{
mNoteDatabaseHelper = new NoteDatabaseHelper(context);
NotificationCompat.Builder mBuilder = new
NotificationCompat.Builder(context)
.setContentTitle("My Notification")
.setContentText("Hello World!");
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, mBuilder.build());
Log.i(NoteApplication.TAG, "Alarm has been called!");
}
In order for me to check this, I am setting it fire after one minute. So I have a ui which sets the alarm 1 minute after the current time.
But this is not working at all. I have declared this on my Application manifest as well:
<receiver
android:name="com.neonwarge.android.note.receivers.NoteAlarmReceiver">
</receiver>
I wonder what I still missed? Also, according to the documentation, if I set the alarm at datetime less than the current datetime the alarm immediately fires. But nothing still.
Here are the relative questions I visited but none of it work:
Any ideas?