如何显示motorola锁屏媒体控件

时间:2017-12-05 16:06:32

标签: android android-notifications motorola android-mediasession

我的应用在我的应用控制的远程设备上播放媒体时发出通知。在大多数设备上,通知(不使用MediaStyle通知)在锁定屏幕上显示正常,但我想在摩托罗拉手机上它没有。我的用户说大多数媒体应用都会在屏幕上显示一些控件但不会显示通知。

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

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

编辑:添加一些代码。

MediaSession:

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);

0 个答案:

没有答案