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

标签 android android-auto

我正在使用桌面主机,我有以下代码将对话推送到该单元,请记住,我在挂起的 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 auto 仪表板中,但我什么也看不到。但在移动设备上我看到了我的通知。让我解释一下发生了什么。在插入汽车之前,我正在创建一条消息。因此,当用户与汽车断开连接时,该方法就会运行。当用户连接到 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/

相关文章:

java - 我如何知道是什么导致我的实体类 getTeamId 中出现空指针

android - 将应用程序发布到 Playstore - 上传 .apk 时出错

android-auto - Android Automotive 支持 Android Auto 和 CarPlay

java - 适用于 SRS 传感器的 Android 汽车 CarSensorManager

java - 寻找合适的设计模式

java - 您可以通过按钮打开选项菜单吗?

android - 查找混淆器生成的混淆堆栈跟踪

Android Auto 自定义应用程序 - 官方

Android 网络浏览器 (ICS) 不调用 MIME 类型的处理程序