我正在使用桌面主机,并且我有以下代码将对话推送到该单元,请记住,我在未决意图上设置了 null,因为我不需要任何挂钩/回调。我只想在 android auto 处于活动状态时发送通知。这是代码不起作用:
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'
}
这是清单的一部分:
<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文件夹中的automobile_app_desc.xml:
<automotiveApp>
<uses name="notification"/>
</automotiveApp>
我在这里关注官方教程
我假设当我创建通知时,物理通知应该出现在 android 自动仪表板中,但我什么也看不到。但在移动设备上,我看到了我的通知。让我解释一下发生了什么。在插入汽车之前,我正在创建一条消息方式。因此,当用户与汽车断开连接时,此方法就会运行。当用户连接到 android auto 时,我期望这个通知应该显示在仪表板上,但它没有但我在移动设备通知托盘上看到它。