Android Auto和Xamarin兼容性

时间:2018-07-24 16:21:14

标签: c# xamarin xamarin.android android-auto

我在将我的应用程序与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

编辑:

我仅有的日志是:

  

[Notification]请参阅setSound()的文档以了解使用的内容   而是使用android.media.AudioAttributes来限定播放的质量   用例

     

[Notification]不建议将流类型用于其他操作   比音量控制

2 个答案:

答案 0 :(得分:1)

我设法让android自动与Xamarin一起使用。

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

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

答案 1 :(得分:0)

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

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

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

这里有一个更完整的代码段,我正在使用一个示例应用程序来在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());
}