gpt4 book ai didi

Android auto - 推送未读对话的代码不起作用

转载 作者:行者123 更新时间:2023-11-29 00:06:23 25 4
gpt4 key购买 nike

我正在使用桌面主机,我有以下代码将对话推送到该单元,请记住,我在未决 Intent 上设置了 null,因为我不需要任何 Hook /回调。我只想在 android auto 处于 Activity 状态时发送通知。这是不起作用的代码:

private void pushAndroidAutoUnreadConversation(String msg) {
// Build a RemoteInput for receiving voice input in a Car Notification
RemoteInput remoteInput = new RemoteInput.Builder(MY_VOICE_REPLY_KEY)
.setLabel(msg)
.build();

// Create an unread conversation object to organize a group of messages
// from a particular sender.
UnreadConversation.Builder unreadConvBuilder =
new UnreadConversation.Builder("my apps conversation")
.setReadPendingIntent(null)
.setReplyAction(null, remoteInput);

unreadConvBuilder.addMessage(msg)
.setLatestTimestamp(System.currentTimeMillis());


Bitmap largeIcon = BitmapFactory.decodeResource(getResources(),
R.drawable.icon);


NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(getApplicationContext())
.setSmallIcon(R.drawable.icon)
.setLargeIcon(largeIcon).setContentTitle(msg);

notificationBuilder.extend(new NotificationCompat.CarExtender()
.setUnreadConversation(unreadConvBuilder.build()));

NotificationManagerCompat msgNotificationManager =
NotificationManagerCompat.from(this);
msgNotificationManager.notify("my_apps_tag",
Integer.parseInt(MY_VOICE_REPLY_KEY), notificationBuilder.build());

}

MY_VOICE_REPLY_KEY 只是一个数字,它是 9675

这是我的 build.gradle 文件:

应用插件:'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "org.myapp.easy"
minSdkVersion 9
targetSdkVersion 21
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('old_proguard-android.txt')
}
}
}

dependencies {
compile files('libs/GoogleAdMobAdsSdk-4.1.1.jar')
compile 'com.android.support:support-v4:21.0.2'
}

这是 list 的一部分:

   <application
android:allowBackup="false"
android:icon="@drawable/icon"
android:label="@string/app_name" >

<meta-data android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc" />

这是我放在 xml 文件夹中的 automotive_app_desc.xml:

 <automotiveApp>
<uses name="notification"/>
</automotiveApp>

我在看官方教程here

我假设当我创建通知时,物理通知应该出现在 android 自动仪表板中,但我什么也没看到。但是在移动设备上我看到了我的通知。让我解释一下发生了什么。在插入汽车之前,我正在创建一条消息方式。因此,当用户与汽车断开连接时,此方法就会运行。当用户连接到 android auto 时,我希望这个通知应该显示在仪表板上,但它没有,但我在移动设备通知托盘上看到它。

最佳答案

终于找到问题了。我正在为未决 Intent 传递 null。它不想那样。我必须为听到的消息和回复的消息制定未决 Intent ,并将它们实际设置在 UnreadConversation.Builder 中,如下所示:

UnreadConversation.Builder unreadConvBuilder =
new UnreadConversation.Builder("reminder note")
.setReadPendingIntent(msgHeardPendingIntent)
.setReplyAction(msgHeardPendingIntent, remoteInput);

所以它似乎不喜欢 setReadPendingIntent 和 setReplyAction 为 null。

关于Android auto - 推送未读对话的代码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33534715/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com