2012-05-29 21 views

回答

4
final NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
final Notification notification = new Notification(R.drawable.icon,"A New Message!",System.currentTimeMillis()); 

notification.defaults=Notification.FLAG_ONLY_ALERT_ONCE+Notification.FLAG_AUTO_CANCEL; 
Intent notificationIntent = new Intent(this, null); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0); 

notification.setLatestEventInfo(AndroidNotifications.this, title,message, pendingIntent); 
notificationManager.notify(NOTIFICATION_ID, notification); 

,而不是传递类意图只是通过为空或使用intent()默认构造函数。如果有帮助,请致电 。

+1

或尝试使用此PendingIntent pendingIntent = PendingIntent.getActivity(this,0,null,0); – MobileEvangelist

0

创建一个空的活动,调用finish()onCreate()并将其设置在PendingIntent中。一个空的(空)一个是不允许的,所以这是你最好的选择,AFAIK。

4

当您创建PendingIntent传递一个空的意图new Intent()

PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0) 

,并设置FLAG_AUTO_CANCEL标志的通知

notification.flags |= Notification.FLAG_AUTO_CANCEL;