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:)
source
share