1

我在将我的应用程序与 Android auto 连接时遇到问题。它是用 Xamarin.Android 制作的。我将 XML 链接到 Android Manifest,但它仍然不起作用。

清单包含:

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

XML 包含:

<?xml version="1.0" encoding="UTF-8" ?>
<automotiveApp>
  <uses name="notification"/>
</automotiveApp>

这就是我构建通知的方式:

NotificationCompat.Builder notificationBuilder = new 
 NotificationCompat.Builder(ApplicationContext);
            notificationBuilder.SetSmallIcon(Resource.Mipmap.ic_push_icon)
                               .SetContentText(msg)
                               .SetWhen(timestamp)
                               .SetContentTitle(content)
                               .SetContentIntent(readIntent)
                               .Extend(new CarExtender()
                                       .SetUnreadConversation(unReadConversation)
                                       .SetColor(ApplicationContext.GetColor(Resource.Color.purple)))
                               .SetChannelId(Fields.CHANNEL_ID)
                               .AddAction(CreateActionFromRemoteInput(replyIntent,remoteInput));
mNotificationManager.Notify(conversation.Id, notificationBuilder.Build());

有什么建议么?谢谢。

编辑:我正在使用 minSdk 21 和 targetSdk 26

编辑:

我唯一的日志是:

[通知] 请参阅 setSound() 的文档,了解如何使用 android.media.AudioAttributes 来限定您的播放用例

[通知] 不推荐使用流类型进行音量控制以外的操作

4

2 回答 2

2

我设法让 android auto 与 Xamarin 一起工作。

我学到的是设置 SetReadPendingIntent() SetReplyAction() 是强制性的。

在 github 上查看我的测试应用程序https://github.com/Verthosa/Xamarin_Android_Auto_Test

于 2019-02-12T11:14:16.250 回答
0

我在您提供的代码片段中没有看到这一点,但看起来缺少的一件事是将消息添加到您的 unReadConversation。

unReadConversation.addMessage(messageString).setLatestTimestamp(currentTimestamp);

文档的发送消息部分中的更多详细信息,很可能与它现在如何处理对话中的多条消息有关。

这是一个更完整的片段,我正在开发一个示例应用程序,以在 Auto 的桌面主机上显示消息。

private void sendNotification(int conversationId, String title, String message,
    String participant, long timestamp) {

    // Build a pending Intent for reads
    PendingIntent readPendingIntent = PendingIntent.getBroadcast(getApplicationContext(),
        conversationId,
        createIntent(conversationId, READ_ACTION),
        PendingIntent.FLAG_UPDATE_CURRENT);

    // Build a Pending Intent for the reply action
    PendingIntent replyPendingIntent = PendingIntent.getBroadcast(getApplicationContext(),
        conversationId,
        createIntent(conversationId, REPLY_ACTION),
        PendingIntent.FLAG_UPDATE_CURRENT);

    // Build a RemoteInput for receiving voice input in a Car Notification
    RemoteInput remoteInput = new Builder(EXTRA_VOICE_REPLY)
        .setLabel(getString(R.string.reply_by_voice))
        .build();

    // Build an Android N compatible Remote Input enabled action.
    NotificationCompat.Action actionReplyByRemoteInput = new NotificationCompat.Action.Builder(
        R.drawable.notification_icon, getString(R.string.reply), replyPendingIntent)
        .addRemoteInput(remoteInput)
        .build();

    // Create the UnreadConversation and add the participant name,
    // read and reply intents.
    UnreadConversation.Builder unReadConversation =
        new UnreadConversation.Builder(participant)
            .setLatestTimestamp(timestamp)
            .setReadPendingIntent(readPendingIntent)
            .setReplyAction(replyPendingIntent, remoteInput);

    // Add the message to the unread conversation
    unReadConversation.addMessage(message).setLatestTimestamp(timestamp);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext())
        .setSmallIcon(R.drawable.notification_icon)
        .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.android_contact))
        .setContentText(message)
        .setWhen(timestamp)
        .setContentTitle(title)
        .setContentIntent(readPendingIntent)
        .extend(new CarExtender()
            .setUnreadConversation(unReadConversation.build())
            .setColor(getApplicationContext().getResources()
                .getColor(R.color.default_color_light))).addAction(actionReplyByRemoteInput);


    mNotificationManager.notify(conversationId, notificationBuilder.build());
}

private Intent createIntent(int conversationId, String action) {
    return new Intent()
        .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
        .setAction(action)
        .putExtra(CONVERSATION_ID, conversationId)
        .setPackage(getPackageName());
}
于 2018-08-03T21:29:26.247 回答