アプリで通知を機能させるのに苦労しています。通知をトリガーするボタン onclicklistener を設定できましたが、今は毎日午後 3 時に自動通知を設定したいと考えています。質問は、通知コードとアラームマネージャー コードをどこに配置すればよいですか? もうボタントリガーを使用していないので。また、サービスのようにバックグラウンドで実行する簡単な方法はありますか?アプリが開いていなくても、毎日特定の時間に通知を発して自動的にユーザーに通知しますか? ありがとう
通知
Intent intent = new Intent(this, GFXSurface.class);
PendingIntent pi2 = PendingIntent.getActivity(this, 0, intent, 0);
String body = "This is a message from the Health Effect";
String title = "The Health Effect";
Notification n = new Notification(R.drawable.notification, body,
System.currentTimeMillis());
n.setLatestEventInfo(this, title, body, pi2);
n.defaults = Notification.DEFAULT_ALL;
nm.notify(uniqueID, n);
finish();
アラームティガー
calendar.set(Calendar.HOUR_OF_DAY, 15);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.SECOND, 0);
AlarmManager am = (AlarmManager) this
.getSystemService(this.ALARM_SERVICE);
PendingIntent pi = PendingIntent.getService(this, 0, new Intent(this,
StatusBar.class), PendingIntent.FLAG_UPDATE_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, pi);