Set Alert Notification

In my Android application, I would like to programmatically configure alaram. Setting the alarm works correctly, but how can I give a notification about this when I receive an alarm.

I looked through the notifications in the developer's guide.

Please find the code.

Calendar cal=Calendar.getInstance();
    Intent alaram=new Intent(Alarmmanager.this,GroupsCheckAlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(Alarmmanager.this, 0, alaram,0);
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),pendingIntent); 
    cal.setTimeInMillis(System.currentTimeMillis()); 

    sendBroadcast(alaram,"setalaram");

and in the broadcast receiver

public class GroupsCheckAlarmReceiver extends BroadcastReceiver{ 

@Override 
 public void onReceive(final Context context, Intent intent) { 
 Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show(); 

 } 

It works fine, but to set up a notification, I need to install a notification manager, which works fine only in the extended activity class, how can I use it when receiving and notifying.

Share your valuable suggestions.

Thanks in advance:)

+3
source share
2 answers

I think you can use contextin onReceiveto find NotificationManagerand call notify:

@Override 
public void onReceive(Context context, Intent intent) {
    NotificationManager notifications = (NotificationManager)
        context.getSystemService(Context.NOTIFICATION_SERVICE);
    notifications.notify( ... );
}

context, !:)

+6

BuzzBox SDK . crontab . - BuzzBox SDK

0

All Articles