我有一个应用程序需要在一天内显示某些事件的通知,具体取决于事件。
我知道该怎么做,如果我需要一项服务在后台保持运行,或者它将在后台运行,在某些日子获得这些事件。
private void Notificar(String descricaoEvento){
NotificationManager notifier = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, "Novo evento no The Point Club", System.currentTimeMillis());
notification.flags |= Notification.DEFAULT_SOUND;
PendingIntent pIntent = PendingIntent.getActivity(this, 0, null, 0);
notification.setLatestEventInfo(this, "Title", descricaoEvento.toString(), pIntent);
notifier.notify(0x007, notification);
}
用这个方法来调用当合适的日期!
感谢您的收听,我将尝试解释我做对的事情:我正在申请一个俱乐部派对,当我打开应用程序时,应用程序会显示下一个庆祝活动,但我希望是在android通知栏中创建一个通知,其中有一个聚会,作为提醒。
当我打开活动以列出事件时,我使用此代码:
Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
int anoAtual= c.get(Calendar.YEAR);
long time = c.getTimeInMillis();
Intent it = new Intent("EXECUTAR_ALARME")
p = PendingIntent.getBroadcast(Eventos.this, 0, it, 0);
AlarmManager alarme = (AlarmManager) getSystemService(ALARM_SERVICE);
alarme.set(AlarmManager.RTC_WAKEUP, time, p);
线
Intent it = new Intent("EXECUTAR_ALARME")
将调用类:
public class Alarm extends BroadcastReceiver{ @Override
public void onReceive(Context contexto, Intent intent) {
NotificationManager notifier =(NotificationManager) contexto.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, "New event in Club", System.currentTimeMillis());
notification.flags |= Notification.DEFAULT_SOUND;
//Intent i = new Intent(this, Eventos.class);
PendingIntent pIntent = PendingIntent.getActivity(contexto, 0, null, 0);
notification.setLatestEventInfo(contexto, "Club", "Teste", pIntent);
notifier.notify(0x007, notification);
}
}
现在我想知道两件事: 1 - 我如何让它在后台运行而不用应用程序打开。2 这段代码只创建了一个警报,我需要创建多个。
谢谢您的帮助。