1

I have a simple app where i am setting an alarm. The alarm works fine. However, when the alarm is set there is no alarm icon in the right taskbar to let the user know the alarm is active. Im not sure how to do this.

Code snippet

 alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE);
 intent = new Intent(context, AlarmReceiver.class);
 pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
 alarmManager.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);

What can i do to show an alarm icon in the right taskbar to show the user that the alarm is active. I will need to show/hide this icon depending if the alarm is turned on/off.

Thank you

EDIT

I tried this and it still doesnt work.

 AlarmManager.AlarmClockInfo ac= new 
 AlarmManager.AlarmClockInfo(System.currentTimeMillis(),
                            pendingIntent);

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      alarmManager.setAlarmClock(ac , pendingIntent);
  } else {
 Intent alarmChanged = new
 Intent("android.intent.action.ALARM_CHANGED");
 context.sendBroadcast(alarmChanged);
 }

1 Answers1

1

you can use AlarmManager.setAlarmClock (AlarmManager.AlarmClockInfo info, PendingIntent operation) for Lolipop and after.

and sendBroadcast(Intent intent); for pre Lolipop

 if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AlarmManager.setAlarmClock(info, mPendingIntent)
    } else {
        setStatusBarIcon(true);
    }

    protected void setStatusBarIcon ( boolean enabled)
    {
        Intent alarmChanged = new
        Intent("android.intent.action.ALARM_CHANGED");
        alarmChanged.putExtra("alarmSet", enabled);
        sendBroadcast(alarmChanged);
    }

also see this

Bishoy Kamel
  • 2,327
  • 2
  • 17
  • 29