Значок действия добавлен в уведомление не отображается - PullRequest
0 голосов
/ 24 марта 2020

enter image description here

Я пытаюсь создать уведомление для входящего вызова. Для этого я добавил два действия в уведомлении. Отображается только текст моего действия. Значок действия не отображается в уведомлении. Я хочу добавить значок рядом с ответом и отменить, который я добавил как AddAction в уведомлении. Я добавил значок действия, как показано ниже,


NotificationCompat.Action answerAction = new NotificationCompat.Action.Builder(R.drawable.answer_call_icon, "Answer", pendingIntent).build();
            NotificationCompat.Action cancelAction = new NotificationCompat.Action.Builder(R.drawable.cancel, "Cancel", pendingIntent).build();

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
                .setLargeIcon((BitmapFactory.decodeResource(getResources(), R.drawable.call_logo)))
                .setContentTitle(intent.getStringExtra("Number"))
                .setSmallIcon(R.drawable.call_logo)
                .setContentIntent(pendingIntent)
                .setAutoCancel(true)
                .setFullScreenIntent(pendingIntent, true)
                .setCategory(NotificationCompat.CATEGORY_CALL)
                .addAction(answerAction)
                .addAction(cancelAction)
                .setPriority(NotificationCompat.PRIORITY_HIGH);
        NotificationManagerCompat nManager = NotificationManagerCompat.from(this);
        nManager.notify(2,builder.build());

Еще один запрос, ниже - мой канал уведомлений,

NotificationChannel   chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_HIGH);
            chan.setLightColor(Color.BLUE);
           chan.setLockscreenVisibility(Notification.FLAG_FOREGROUND_SERVICE);
            chan.setImportance(NotificationManager.IMPORTANCE_HIGH);
            chan.setSound(defaultRingToneUri,audioAttributes);
 chan.enableLights(true);
            chan.shouldShowLights();
            chan.setVibrationPattern(vibrate);
            chan.enableVibration(true);
            Context context=getApplicationContext();
            NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            assert manager != null;
            manager.createNotificationChannel(chan);

Невозможно получить рингтон при получении уведомления. Правильно ли я настраиваю звук? Кто-нибудь, пожалуйста, помогите мне решить эту проблему ... Опубликовано 2 дня go .. но до сих пор не смог найти решение.

Ответы [ 3 ]

0 голосов
/ 01 апреля 2020

Согласно Уведомлениям в Android N сообщении в блоге :

Действия по уведомлению также получили редизайн и теперь находятся в визуально отдельной панели под уведомлением.

Вы заметите, что значки не присутствуют в новых уведомлениях; вместо этого больше места предусмотрено для самих меток в ограниченном пространстве тени уведомлений. Однако значки действий уведомления все еще требуются и продолжают использоваться в более старых версиях Android и на устройствах, таких как Android Износ.

Поэтому ожидается, что вы не увидите значки, связанные с действиями по уведомлению.

0 голосов
/ 02 апреля 2020

Если вам нужно больше гибкости при создании макета уведомления, go для пользовательского.

Ссылка: https://developer.android.com/training/notify-user/custom-notification

Используйте Drawable слева / Правильный вариант, чтобы установить значок с текстом в кнопке.

// Get the layouts to use in the custom notification
RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_small);
RemoteViews notificationLayoutExpanded = new RemoteViews(getPackageName(), R.layout.notification_large);

// Apply the layouts to the notification
Notification customNotification = new NotificationCompat.Builder(context, CHANNEL_ID)
        .setSmallIcon(R.drawable.notification_icon)
        .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
        .setCustomContentView(notificationLayout)
        .setCustomBigContentView(notificationLayoutExpanded)
        .build();
0 голосов
/ 24 марта 2020

Как я понимаю: у вас проблема с уведомлением, вы можете использовать этот метод:

 private void showSmallNotification(NotificationCompat.Builder mBuilder, int icon, String title, String message, String timeStamp, PendingIntent resultPendingIntent, Uri alarmSound) {

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    inboxStyle.addLine(message);

    Notification notification;
    notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent)
            .setSound(alarmSound)
            .setStyle(inboxStyle)
            .setWhen(getTimeMilliSec(timeStamp))
            .setContentText(message)
            .build();

    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Constant.NOTIFICATION_ID, notification);
}

или этот:

 private void showBigNotification(Bitmap bitmap, NotificationCompat.Builder mBuilder, int icon, String title, String message, String timeStamp, PendingIntent resultPendingIntent, Uri alarmSound) {
    NotificationCompat.BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
    bigPictureStyle.setBigContentTitle(title);
    bigPictureStyle.setSummaryText(Html.fromHtml(message).toString());
    bigPictureStyle.bigPicture(bitmap);
    Notification notification;
    notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent)
            .setSound(alarmSound)
            .setStyle(bigPictureStyle)
            .setWhen(getTimeMilliSec(timeStamp))

            .setContentText(message)
            .build();

    NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(Constant.NOTIFICATION_ID_BIG_IMAGE, notification);
}
...