如何为 android 自动模拟器发送 google 地图通知?
How to send a google map notification for android auto simulator?
我正在为 Android Auto
开发应用程序。我想发送这样的地图通知(我还没有实现大视图)
我用下面的代码试了一下。但是发送地图导航通知失败
private void sendNotificationForConversation(Conversation conversation) {
// A pending Intent for reads
double latitude = 31.249351;
double longitude = 121.45905;
Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri
.parse("http://maps.google.com/maps?saddr="
+ latitude + ","
+ longitude + "&daddr="
+ 31.186371 + "," + 121.489885));
notificationManager = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.notification_icon, "Kohls store ahead", 1000);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.activity_kcc);
contentView.setTextViewText(R.id.hello, "This is the KCC layout");
notification.contentView = contentView;
PendingIntent readPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = readPendingIntent;
notification.flags |= Notification.FLAG_AUTO_CANCEL; // clear the notification
notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
notification.defaults |= Notification.DEFAULT_SOUND; // Sound
// Build a RemoteInput for receiving voice input in a Car Notification
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
.setLabel(getApplicationContext().getString(R.string.notification_reply))
.build();
// Building a Pending Intent for the reply action to trigger
PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(),
conversation.getConversationId(),
getMessageReplyIntent(conversation.getConversationId()),
PendingIntent.FLAG_UPDATE_CURRENT);
// Create the UnreadConversation and populate it with the participant name,
// read and reply intents.
NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder =
new NotificationCompat.CarExtender.UnreadConversation.Builder(conversation.getParticipantName())
.setLatestTimestamp(conversation.getTimestamp())
.setReadPendingIntent(readPendingIntent)
.setReplyAction(replyIntent, remoteInput);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
.setContent(contentView)
.setContentIntent(readPendingIntent)
.extend(new NotificationCompat.CarExtender()
.setUnreadConversation(unreadConvBuilder.build()));
MessageLogger.logMessage(getApplicationContext(), "Sending notification "
+ conversation.getConversationId() + " conversation: " + conversation);
notificationManager.notify(conversation.getConversationId(), builder.build());
}
有了这个,我在模拟器上得到了一个空的通知,状态栏上没有任何可见的东西。单击此通知后,我想在 android 汽车设备上显示导航地图。我该如何解决这个问题?
提前致谢!
我觉得你现在做不到;您无法直接启动 Android 汽车的 Google 地图 activity。我尝试通过以下方式启动 Direction 意图:
Uri gmmIntentUri = Uri.parse("google.navigation:q=San+Francisco");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
mapIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mapIntent);
但它似乎不起作用。我没有真正的主机,所以我不确定这是否适用于真实设备,但这是我最好的猜测。
我正在为 Android Auto
开发应用程序。我想发送这样的地图通知(我还没有实现大视图)
我用下面的代码试了一下。但是发送地图导航通知失败
private void sendNotificationForConversation(Conversation conversation) {
// A pending Intent for reads
double latitude = 31.249351;
double longitude = 121.45905;
Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri
.parse("http://maps.google.com/maps?saddr="
+ latitude + ","
+ longitude + "&daddr="
+ 31.186371 + "," + 121.489885));
notificationManager = (NotificationManager) getApplicationContext()
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.notification_icon, "Kohls store ahead", 1000);
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.activity_kcc);
contentView.setTextViewText(R.id.hello, "This is the KCC layout");
notification.contentView = contentView;
PendingIntent readPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentIntent = readPendingIntent;
notification.flags |= Notification.FLAG_AUTO_CANCEL; // clear the notification
notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
notification.defaults |= Notification.DEFAULT_SOUND; // Sound
// Build a RemoteInput for receiving voice input in a Car Notification
RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
.setLabel(getApplicationContext().getString(R.string.notification_reply))
.build();
// Building a Pending Intent for the reply action to trigger
PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(),
conversation.getConversationId(),
getMessageReplyIntent(conversation.getConversationId()),
PendingIntent.FLAG_UPDATE_CURRENT);
// Create the UnreadConversation and populate it with the participant name,
// read and reply intents.
NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder =
new NotificationCompat.CarExtender.UnreadConversation.Builder(conversation.getParticipantName())
.setLatestTimestamp(conversation.getTimestamp())
.setReadPendingIntent(readPendingIntent)
.setReplyAction(replyIntent, remoteInput);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
.setContent(contentView)
.setContentIntent(readPendingIntent)
.extend(new NotificationCompat.CarExtender()
.setUnreadConversation(unreadConvBuilder.build()));
MessageLogger.logMessage(getApplicationContext(), "Sending notification "
+ conversation.getConversationId() + " conversation: " + conversation);
notificationManager.notify(conversation.getConversationId(), builder.build());
}
有了这个,我在模拟器上得到了一个空的通知,状态栏上没有任何可见的东西。单击此通知后,我想在 android 汽车设备上显示导航地图。我该如何解决这个问题?
提前致谢!
我觉得你现在做不到;您无法直接启动 Android 汽车的 Google 地图 activity。我尝试通过以下方式启动 Direction 意图:
Uri gmmIntentUri = Uri.parse("google.navigation:q=San+Francisco");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
mapIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mapIntent);
但它似乎不起作用。我没有真正的主机,所以我不确定这是否适用于真实设备,但这是我最好的猜测。