汽车和Android兼容性Xamarin

问题描述 投票:1回答:2

我有一个问题,我的应用程序与Android自动连接。它与Xamarin.Android制成。我挂了XML到Android清单,但它仍然无法正常工作。

该清单包含:

<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出线您的播放使用情况的文件

[通知]流类型的使用是不推荐超过音量控制的其它操作

c# xamarin xamarin.android android-auto
2个回答
1
投票

我设法让机器人自动工作与Xamarin。

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

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


0
投票

我没有看到这一点,你所提供的代码片段,但它看起来像一两​​件事,缺少的只是添加消息到您unReadConversation。

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

docs的发送消息节的更多细节,并最有可能涉及到如何它现在可以在一个会话处理多个消息。

下面是我对一个示例应用程序的工作,以显示桌面头单元的自动上的消息更完整的片段。

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());
}
© www.soinside.com 2019 - 2024. All rights reserved.