Действия уведомления не отображаются в сервисном уведомлении - PullRequest
0 голосов
/ 27 января 2020

У меня есть уведомление для службы переднего плана с 2-мя действиями, но они не отображаются при запуске службы. Я тоже не могу расширить уведомление. Вот мой код:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            registerNotificationChannel();
            //sendMessageToNotification("boot",false,false);
            Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
            Intent serviceIntent = new Intent(getApplicationContext(), LimindoService.class);
            serviceIntent.putExtra("action","actionclose");
            serviceIntent.putExtra("ServiceIntent", true);
            serviceIntent.setAction(ACTION_CLOSE);
            Intent serviceIntent2 = new Intent(getApplicationContext(), LimindoService.class);
            serviceIntent2.putExtra("action","actionreconnect");
            serviceIntent2.putExtra("ServiceIntent", true);
            serviceIntent2.setAction(ACTION_RECONNECT);

            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(MainActivity.class);
            stackBuilder.addNextIntent(notificationIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent servicePendingIntent = PendingIntent.getService(getApplicationContext(),REQUEST_CODE_CLOSE, serviceIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent servicePendingIntent2 = PendingIntent.getService(getApplicationContext(),REQUEST_CODE_RECONNECT, serviceIntent2, PendingIntent.FLAG_UPDATE_CURRENT);
            NotificationCompat.Action action = new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_close_clear_cancel,getString(R.string.close),servicePendingIntent).build();
            NotificationCompat.Action action2 = new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_rotate,getString(R.string.reconnect),servicePendingIntent2).build();
            notification = new NotificationCompat.Builder(getApplicationContext(), NOTIFICATION_CHANNEL_ID)
                    .setContentTitle(getText(R.string.notification_title))
                    .setContentText(getText(R.string.notification_message))
                    .setSmallIcon(R.drawable.vn_logo_c02)
                    .setContentIntent(resultPendingIntent)
                    .setTicker(getText(R.string.ticker_text))
                    .setChannelId(NOTIFICATION_CHANNEL_ID)
                    .addAction(action)
                    .addAction(action2)
                    .setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
                            .setShowActionsInCompactView(0,1))
                    .setWhen(0)
                    .setOngoing(true)
                    .build();
            startForeground(SERVICE_NOTIFICATION_ID, notification);
            NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            notificationManager.notify(SERVICE_NOTIFICATION_ID, notification);

        }
...