2017-01-25 6 views
0

クリック後に通知を消したい場合は、新しいアクティビティに行きたくありません。これは私が通知を構築する方法である:クリック後に通知が消える方法

public static void getSynchronizeNotification(Context context, DataResponse dataResponse){ 
    Bitmap Largeicon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher); 
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.cancel(NOTIFICATION_SYNCHRONIZE_ID); 

Intent in = new Intent(String.valueOf(context)); 
Intent intent = new Intent(context, MainActivity.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, in, 0); 
Notification notification = new Notification.Builder(context) 
     .setContentTitle(context.getString(R.string.app_name)) 
     .setSmallIcon(R.drawable.ic_launcher) 
     .setContentIntent(pendingIntent) 
     .setContentText("Zmiany po synchronizacji...") 
     .setStyle(new Notification.BigTextStyle().bigText(buildNotificationAfterSynchronizeText(dataResponse))) 
     .setLargeIcon(Largeicon) 
     .setAutoCancel(true) 
     .setVibrate(vibratePattern) 
     .setSound(alarmSound) 
     .setPriority(Notification.PRIORITY_MAX) 
     .build(); 
notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; 
notificationManager.notify(NOTIFICATION_SYNCHRONIZE_ID, notification); 

}

+0

はsetContentIntent(pendingIntent)を除去してい動作します助けてくれる? –

+0

@KarthikCP私がetContentIntent(pendingIntent)のとき、私はそれが起こらない通知をクリックすると、私はスワイプ時にnotyfication dissapear –

答えて

0

私はこの変更: PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, in, 0); 

をし、それが

関連する問題