2016-10-26 6 views
1

두 개의 버튼으로 알림을 보내려고합니다. 알림을 표시 할 수 있습니다.버튼이있는 Android 알림 클릭 제거 알림

setOnClickPendingIntent를 사용했는데 버튼을 클릭하면 알림을 제거 할 수 없습니다.

나는 notification.flags |= Notification.FLAG_AUTO_CANCEL;notificationManager.cancel(id);을 시도했지만 제대로 작동하지 않았습니다. 나는 무엇을 잘못하고 있는지 안내해주십시오. setContentIntent을 클릭하면 제거가되지만 단추를 클릭하지 않습니다. 여기

PendingIntent pendingIntent; 
       Intent intent = new Intent(this, ChatListActivity.class); 
       intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
       intent.putExtra("accept", "true"); 
       pendingIntent = PendingIntent.getActivity(this, 0, intent, 
         PendingIntent.FLAG_CANCEL_CURRENT); 
       // Create remote view and set bigContentView. 
       RemoteViews expandedView = new RemoteViews(getApplicationContext().getPackageName(), 
         R.layout.notification_message_remote); 

       expandedView.setOnClickPendingIntent(R.id.btn_accept, pendingIntent); 
       Notification notification = new NotificationCompat.Builder(getApplicationContext()) 
         //Vibration 
         .setVibrate(new long[]{1000, 1000, 1000, 1000, 1000}) 
         //LED 
         .setLights(Color.RED, 3000, 3000) 
         //Ton 
         .setSound(Settings.System.DEFAULT_NOTIFICATION_URI) 
         .setColor(getResources().getColor(R.color.colorAccent)) 
         .setSmallIcon(R.drawable.icon) 
         .setAutoCancel(true) 
         .setContentIntent(pendingIntent) 
         .setContentText(remoteMessage.getData().get("Title")) 
         // .setStyle(new NotificationCompat.BigTextStyle().bigText(mTitle)) 
         .setContentTitle("Notification").build(); 

       notification.bigContentView = expandedView; 
       // hide the notification after its selected 
       //notification.flags |= Notification.FLAG_AUTO_CANCEL; 
       //notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; 
       NotificationManager notificationManager = 
         (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
       notification.flags |= Notification.FLAG_AUTO_CANCEL; 
       notificationManager.notify(0, notification); 
       notificationManager.cancel(0); 
+0

당신이 (notificationManager.cancelAll를 시도 않았다)이 시도 코드; –

+0

그것의 작동하지 않습니다 –

답변

1

이 ChatListActivity.onCreate()

NotificationManager manager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); 
//in this case, it should be 0 
manager.cancel(notificationId); 
//dismiss notification panel 
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 
context.sendBroadcast(it); 
+0

고마워요 많은 친구 .. 그 근무 ... –