我遵循了 Udacity 上的教程和 Android auto 的开发者网站。我正在使用 DVU 进行测试。通知不会出现在 DHU 上,但会出现在手机上,这是我的代码:
使用 GcmListenerService:
final PendingIntent contentIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT
| PendingIntent.FLAG_ONE_SHOT);
final PendingIntent contentIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT
| PendingIntent.FLAG_ONE_SHOT);
Intent msgHeardIntent = new Intent()
.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
.setAction("com.xyz.abc.MY_ACTION_MESSAGE_HEARD")
.putExtra("conversation_id", 9999);
PendingIntent msgHeardPendingIntent =
PendingIntent.getBroadcast(getApplicationContext(),
9999,
msgHeardIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder =
new NotificationCompat.CarExtender.UnreadConversation.Builder("TestAndroidAuto")
.setReadPendingIntent(msgHeardPendingIntent);
unreadConvBuilder.addMessage(description);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSmallIcon(R.drawable.ic_stat_notification_icon)
.setContentTitle(title)
.setTicker(ticker)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(description))
.setContentText(description)
.setDefaults(Notification.DEFAULT_ALL);
mBuilder.extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConvBuilder.build()));
mBuilder.setContentIntent(contentIntent);
mBuilder.setAutoCancel(true);
mNotificationManager = NotificationManagerCompat.from(getApplicationContext());
mNotificationManager.notify(REMOTE_NOTIFICATION_ID, mBuilder.build());
我不明白我哪里出错了,因为这是相当新的。