Clicking Android Notification Actions does not close Notification drawer

后端 未结 5 1744
谎友^
谎友^ 2020-12-13 08:23

I am adding a Notification to System bar using the NotificationCompat library. This Notification has two action buttons. Also, AutoCancel() propert

5条回答
  •  余生分开走
    2020-12-13 09:14

    try this:

        NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
        Intent notificationIntent = new Intent(this.getBaseContext(), MainActivity.class);
        notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Builder mNotifyBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(
                getApplicationContext())
                .setTicker(getApplicationContext().getText(R.string.app_name))
                .setContentTitle(getApplicationContext().getText(R.string.app_name))
                .setContentText(getApplicationContext().getText(R.string.text))
                .setSmallIcon(R.drawable.smallicon)
                .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.mipmap.ic_launcher))
                .setContentIntent(pendingIntent)
                .setAutoCancel(true)
                .setVibrate(new long[]{150, 300});
        mNotifyBuilder.build().flags |= Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(1, mNotifyBuilder.build());
    

提交回复
热议问题