4

알림을 클릭하면 자동으로 내 알림을 취소하고 싶습니다. 다음 코드는 Android 롤리팝 기기를 제외한 모든 기기에서 잘 작동합니다. Lollipop 기기에서 알림은 사용자가 스 와이프 한 경우에만 표시됩니다.Android Lollipop 알림 자동 취소 기능이 작동하지 않습니다.

@SuppressWarnings ("중단") 공공 무효의 sendNotification에 (INT ID가) {

NotificationCompat.Builder mBuilder = 
      new NotificationCompat.Builder(this) 
      .setSmallIcon(R.drawable.ic_launcher) 
      .setContentTitle("Test") 
      .setContentText("Jump to next screen") 
      .setDefaults(Notification.DEFAULT_SOUND) 
      .setAutoCancel(true); 

    mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE; 


    // Creates an explicit intent for an Activity in your app 
    Intent resultIntent = new Intent(this, NextActivity.class); 

    resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK); 
    PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, 
            resultIntent, 0); 
    //PendingIntent.FLAG_UPDATE_CURRENT 

    mBuilder.setContentIntent(resultPendingIntent); 
    NotificationManager mNotificationManager = 
     (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
    // id, if there is a need to update the notification later on. 
    mNotificationManager.notify(id, mBuilder.build()); 

    Log.v(TAG, "Notification ID value " + id); 

    //mNotificationManager.cancel(id); 
} 

이 코드에서 누락은 무엇입니까?

+0

심지어 내가이 문제를 참조하여 설정할 수있는 특별한 조건을 설정하려는 경우

NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancelAll(); 

을 다음을 수행합니다. 해결 방법을 찾을 수 있었습니까? 내가보기에, 그것으로 제거되고 하나의 새로 고침은 알림 센터에서 발생합니다. – Ayyappa

+0

팔로우. 나는 너무 붙어있다. 이 모든 문제를 아직 파악하지 못했지만 아직 해결되지 않았습니다. 현재 타이머를 실행하고 타이머가 만료 된 후 모든 알림을 취소합니다. – LokiDroid

답변

0

나에게 잘 어울립니다. 내 자동 취소는 여전히 5.0.2에서 작동합니다.

public static void notif(int id, String title, String text, Context context, Class activity) { 
    // get an instance of the NotificationManager service 
    if (mNotifyMgr == null) 
     mNotifyMgr = (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE); 

    Intent intent = new Intent(context, activity); 
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 

    PendingIntent notifIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

    NotificationCompat.Builder mBuilder = 
     new NotificationCompat.Builder(context) 
      .setSmallIcon(R.mipmap.launcher) 
      .setContentTitle(title) 
      .setContentText(text) 
      .setContentIntent(notifIntent); 
    mNotifyMgr.notify(id, mBuilder.build()); 
} 
0

수정 다음 : 내가 당신에게 내 코드의 일부를 줘 보자 setAutoCancel (참) -> (false)를 setAutoCancel; 다음 행동 활동에 당신이

intent.putExtra("key", "value") 
관련 문제