イベントに応じて、1 日のうちに特定のイベントの通知を表示する必要があるアプリケーションがあります。
バックグラウンドでサービスを実行し続ける必要がある場合、または特定の日にこれらのイベントを取得してバックグラウンドで実行する場合は、その方法を知っています。
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);
}
}
ここで、2 つのことを知りたいと思います。1 - アプリケーションで開かずに、バックグラウンドで実行したままにしておくにはどうすればよいですか。2 このコードはアラームのみを作成し、複数作成する必要があります。
助けてくれてありがとう。