2016-02-12 74 views
0

後,我有我的Android Studio項目的一段代碼:Android通知不會消失點擊

private void sendNotification(String msg) { 
     mNotificationManager = (NotificationManager) 
       this.getSystemService(Context.NOTIFICATION_SERVICE); 

     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
       new Intent(this, MainActivity.class), 0); 

     NotificationCompat.Builder mBuilder = 
       new NotificationCompat.Builder(this) 
         // .setSmallIcon(R.drawable.ic_stat_gcm) 
         .setContentTitle("New updates from StoriesCity!") 
         .setSmallIcon(R.drawable.ic_launcher) 
         .setStyle(new NotificationCompat.BigTextStyle() 
           .bigText(msg)) 
         .setContentText(msg); 


     mBuilder.setContentIntent(contentIntent); 
     mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); 
    } 

它的工作很好,我看到了通知,但是當我點擊它它不會消失。 。

也許是因爲我使用.notify? 請幫我修改一下代碼,使點擊失敗。

我是個初學者:)

回答

0

設置標誌FLAG_CANCEL_CURRENT代替0

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
      new Intent(this, MainActivity.class), PendingIntent.FLAG_CANCEL_CURRENT); 

而且

.setAoutoCancel(true)