我有在状态栏中显示通知的代码。我知道可以通过setLatestEventInfo()
再次调用来完成更新,但我希望每半小时完成一次更新。
我如何跟踪时间?有人知道有什么功能吗?
我什至想过使用每半小时递增一次的计数器,但再次检索时间是一个问题。
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.index1;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence notificationTitle = "My notification";
CharSequence notificationText = "Hello World!";
Intent notificationIntent = new Intent(this, NotificationAppActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, notificationTitle, notificationText, contentIntent);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification);
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_LIGHTS;
}