报警接收器的Android组的通知 [英] set notification on alarm receiver android
问题描述
在我的Android应用程序,我想以编程方式设置一个alaram。
设置报警器工作正常,但如何申请通知本上recieving报警。
In my android application i would like to set an alaram programmatically. Setting alarm is working properly but how can i apply notification to this on recieving alarm.
我在开发者指南通过通知了。
I have gone through notifications in developer guide.
请找到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");
和广播接收器
public class GroupsCheckAlarmReceiver extends BroadcastReceiver{
@Override
public void onReceive(final Context context, Intent intent) {
Toast.makeText(context, "Alarm worked.", Toast.LENGTH_LONG).show();
}
据工作正常,但设置的通知我需要设置通知管理器,它只有在活动推广类的工作很好,我怎么可以用它接收和通知。
It is working fine but to set notification i need to set notification manager which works fine only in activity extended class ,how can i use it on receive and notify.
请分享您的宝贵建议。
在此先感谢:)
推荐答案
我想你可以用你的背景
在的onReceive
找到 NotificationManager
和呼叫通知
:
I think you can use your context
in onReceive
to find the NotificationManager
and call notify
:
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager notifications = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
notifications.notify( ... );
}
如果你有一个上下文
你可以做任何事情! :)
If you have a Context
you can do just about anything! :)
这篇关于报警接收器的Android组的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!