0

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?

Community
  • 1
  • 1
Neon Warge
  • 1,817
  • 6
  • 29
  • 53
  • 1
    I created a quick HelloWorld app using the same functions as yours (just changed the AlarmManager.INTERVAL_FIFTEEN_MINUTES to 60*1000 for quick testing) and the alarm fires perfectly well. I am also seeing the notification (you need to call the .setSmallIcon() so that the notification is seen) . Are you sure you can't see the log either? I can share my code on github in case you want. – Nilesh Pawar May 03 '15 at 06:57
  • Yes please, I will be very glad as well. Also, I am running on the debug mode and place breakpoints on the NoteAlarmReceiver, but it is not passing through there, hence it is not being called at all. Maybe due the alarm not triggering it. – Neon Warge May 03 '15 at 07:00
  • uploaded to the AlarmManager folder in : https://github.com/NileshPawarCitrix/for-stackoverflow – Nilesh Pawar May 03 '15 at 07:11

0 Answers0