我正在为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 auto car 设备上显示导航地图。我该如何解决这个问题?
提前致谢!