0

当媒体在我的应用控制的远程设备上播放时,我的应用会收到通知。在大多数设备上,通知(不使用MediaStyle通知)在锁定屏幕上显示得很好,但我猜在摩托罗拉手机上它不会。我的用户说大多数媒体应用程序会在屏幕上显示一些控件,但不会显示通知。

如何确保我的应用显示这些控件?我没有要测试的摩托罗拉手机。

我已经在创建MediaSessionCompat,例如在 Android Wear 上,我可以很好地看到我的控件,而无需任何额外的代码。

编辑:添加一些代码。

媒体会话:

mediaSession = new MediaSessionCompat(MediaNotificationService.this, TAG);
mediaSession.setCallback(new MediaSessionCallback());
mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS | MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder();
metadataBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, mediaTitle);
metadataBuilder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, image);
mediaSession.setMetadata(metadataBuilder.build());
setMediaSessionState(playStateStatus);
mediaSession.setActive(true);

和通知:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
                .setSmallIcon(R.drawable.ic_stat_notification_icon)
                .setOngoing(true)
                .setAutoCancel(false)
                .setContentIntent(someActivityIntent)
                .setPriority(NotificationCompat.PRIORITY_LOW);
RemoteViews smallNotificationViews = new RemoteViews(this.getPackageName(),R.layout.playing_notification);
RemoteViews bigNotificationViews = new RemoteViews(this.getPackageName(),R.layout.playing_notification_big);
if (OSUtils.lollipopOrHigher) {
    mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
}
//set a bunch of pending intents for buttons inside the layouts
... //code to create notification channel if it doesn't exist
notification = mBuilder.build();
notification.contentView = smallNotificationViews;
if (OSUtils.isJellyBeanOrAbove) {
    notification.bigContentView = bigNotificationViews;
}
notify(notification);
startForeground(NOTIFICATION_ID, notification);
4

0 回答 0