我努力让通知在我的应用中发挥作用。我能够设置一个按钮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);