java - 通知中添加的操作图标未显示

标签 java android notifications notification-channel

enter image description here

我正在尝试为来电创建通知。为此,我在通知中添加了两个操作。仅显示我的操作文本。通知中不显示操作图标。 我想在“答案”附近添加图标并取消我在“通知”中添加为“添加操作”的图标。我添加了如下所示的操作图标,


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());

还有一个查询, 以下是我的通知 channel ,

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天前发布..但到目前为止还找不到解决方案。

最佳答案

根据 Notifications in Android N blog post :

Notification actions have also received a redesign and are now in a visually separate bar below the notification.

You’ll note that the icons are not present in the new notifications; instead more room is provided for the labels themselves in the constrained space of the notification shade. However, the notification action icons are still required and continue to be used on older versions of Android and on devices such as Android Wear.

因此,预计您不会看到与通知操作关联的图标。

关于java - 通知中添加的操作图标未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60831792/

相关文章:

java - 使用 Java8 Streams 求和列表中各点之间的距离

java - 如何检索相关的 Odata 实体 Odata4j

java - 没有 GCM 的 Android 推送通知可以在后台服务中工作,但推送通知会在预计时间之前显示

java - 使用多个 WSDL (xmlbeans) 处理共享命名空间

android - 如果 Context 被销毁,SharedPreference 是否会被销毁?

android - 为 Android 应用程序实现密码锁

android - Espresso 为 edittext 设置光标

android - 在通知栏中通知几秒钟?

ios - 快速 iOS 本地通知

java - @事务: Is there a way that hibernate can persist child transacttion when parent fails