2012-05-29 32 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;