繁体   English   中英

Android Auto 中不显示通知

[英]Notifications are not displayed in Android Auto

我在尝试在 Android Auto 中显示通知时遇到了麻烦。

我已经按照配置指南添加了对 Android Auto 1的支持和 Android Auto 2中的通知支持。 但是我不清楚通知的文档。 因此,如果我的代码有问题,我会寻求帮助。

目前,通知显示在设备上,但不在 Android auto 上。 我正在使用 Desktop Head Unit 3进行测试

谢谢!

  fun builder(subject : String, title: String, context: Context) : String {

    val ACTION_REPLY = "com.example.native_notification.Notifications.reply"
    val ACTION_MARK_AS_READ = "com.example.native_notification.Notifications.mark_as_read"

    try {
        //Create the NotificationChannel
        val channelId = "NOTIFICATION_AUTO";
        val name = "Notificaciones android auto";
        val descriptionText = "Notify about status of your services";
        val importance = NotificationManager.IMPORTANCE_HIGH
        val mChannel = NotificationChannel(channelId, name, importance)
        mChannel.description = descriptionText;
        // Register the channel with the system; you can't change the importance
        // or other notification behaviors after this
        val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

        notificationManager.createNotificationChannel(mChannel)

        val intent = Intent().apply {
            putExtra(EXTRA_MESSAGE, "intent working")
        }

        val pendingIntent = PendingIntent.getActivity(context, 2 ,intent,PendingIntent.FLAG_UPDATE_CURRENT)


        val icon: Icon = Icon.createWithResource(context, R.drawable.ic_logo)

        val longMessage: Long = 1

        var action: Notification.Action =
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                Notification.Action.Builder(icon,
                    "Ok,", pendingIntent)
                    .setSemanticAction(Notification.Action.SEMANTIC_ACTION_MARK_AS_READ)
                    .build()
            } else {
                TODO("VERSION.SDK_INT < P")
            }


        val p = Person.Builder().setName("Gopass").build()

        val style: Notification.Style = Notification.MessagingStyle(p)
            .setConversationTitle("this is a title")
            .addMessage(Notification.MessagingStyle
                .Message("this is the text", longMessage, p))

        val newMessageNotification = Notification.Builder(context, channelId)
            .setContentTitle(title)
            .setContentText(subject)
            .setCategory(Notification.CATEGORY_MESSAGE)
            .setSmallIcon(R.drawable.ic_logo)
            .setLargeIcon(icon)
            .setStyle(style)
            .setVisibility(Notification.VISIBILITY_PUBLIC)
            .addAction(action)
            .extend(Notification.CarExtender())
            .build()
            
        return notificationManager.notify(0, newMessageNotification).toString();

    }
    catch(ex: Exception) {
        return ex.toString()
    }
}

要在车内显示通知,您需要添加

CarAppExtender.Builder()
                    .setImportance(NotificationManager.IMPORTANCE_HIGH)
                    .build()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM