Tôi đang cố hiển thị thông báo thông qua Android Auto. Thông báo hiện hiển thị trên điện thoại của tôi. Tuy nhiên, nó là không phải hiển thị trên trình mô phỏng Android Auto. Đây là một ứng dụng truyền thông.Thông báo tự động Android không hiển thị
automotvie_app_desc.xml:
<automotiveApp>
<uses name="media"/>
</automotiveApp>
Mã này là trong MediaBrowserService
lớp học của tôi:
private Notification postNotification(AutoNotificationHelper.Type type) {
Log.d(TAG, "Post Notification");
Notification notification = AutoNotificationHelper.createMenuErrorNotification(
getApplicationContext(), type, mSession);
if (notification != null) {
mNotificationManager.notify(TAG, NOTIFICATION_ID, notification);
}
return notification;
}
Đây là nơi thông báo được tạo ra:
static Notification createMenuErrorNotification(Context context, Type type,
MediaSessionCompat mediaSession) {
MediaControllerCompat controller = mediaSession.getController();
MediaMetadataCompat mMetadata = controller.getMetadata();
PlaybackStateCompat mPlaybackState = controller.getPlaybackState();
if (mMetadata == null) {
Log.e(TAG, "MetaData is null");
}
if (mPlaybackState == null) {
Log.e(TAG, "Playback state is null");
}
if (type.equals(Type.MENU_ERROR)) {
Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.error);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context.getApplicationContext());
notificationBuilder.extend(new android.support.v4.app.NotificationCompat.CarExtender())
.setStyle(new NotificationCompat.MediaStyle()
.setMediaSession(mediaSession.getSessionToken()))
.setSmallIcon(R.drawable.error)
.setShowWhen(false)
.setContentTitle(context.getString(R.string.title))
.setContentText(context.getString(R.string.message))
.setLargeIcon(icon)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
return notificationBuilder.build();
}
return null;
}
tôi thiếu gì có được điều này để hiển thị trên màn hình tự động và không hiển thị trên điện thoại?
Điều này vẫn chỉ hiển thị thông báo trên điện thoại và không hiển thị trên đơn vị đầu tự động. – mattfred