0

我在跟踪之类的计时器上设置了通知,仅每 20 秒重复一次。

它在第一次迭代期间显示通知,并且日志记录显示它每 20 秒通过一次代码,但在第一次之后通知在手机上不可见。不知道为什么,有什么想法吗?

NotificationManager notificationManager = (NotificationManager)getBaseContext().getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, "App is running on this Phone. ", 1);

String title = "App";

Intent notificationIntent = new Intent(getBaseContext(), MyActivity.class);
// set intent so it does not start a new activity  
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

PendingIntent intent2 = PendingIntent.getActivity(getBaseContext(), 0,notificationIntent, 0);

notification.setLatestEventInfo(getBaseContext(), title, "App is running on this Phone. ", intent2);
//notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_ONGOING_EVENT;

notificationManager.notify(0, notification);

Log.e("APP_DEBUG: doNotify finished", "APP_DEBUG: doNotify finished");
4

0 回答 0