我们在尝试向app用户发送定期消息时遇到问题

时间:2013-01-17 16:58:58

标签: android android-intent

我在跟踪计时器上设置了通知,但每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");

0 个答案:

没有答案