问题
I am stuck in this problem from last 6 days after deep research through media session I found this important line
- Album artwork for display on the lock screen. The image is a bitmap with a maximum size of 320x320dp (if larger, it's scaled down).
Now, Here is my code of media session and Notification...
MEDIA SESSION
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void initMediaSession() {
if (mediaSessionManager != null) return;
mediaSessionManager = (android.media.session.MediaSessionManager) getSystemService(Context.MEDIA_SESSION_SERVICE);
mediaSession = new MediaSessionCompat(getApplicationContext(), "AudioPlayer");
transportControls = mediaSession.getController().getTransportControls();
mediaSession.setActive(true);
mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
updateMetaData();
//=============callBacks of Methods==============================//
mediaSession.setCallback(new MediaSessionCompat.Callback() {
@Override
public void onPlay() {
play();
super.onPlay();
}
@Override
public void onSkipToNext() {
next();
super.onSkipToNext();
}
@Override
public void onSkipToPrevious() {
back();
super.onSkipToPrevious();
}
});
}
method of METADATA...
public void updateMetaData(){
MediaMetadataCompat.Builder builder = new MediaMetadataCompat.Builder();
builder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, Artist);
builder.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, Album);
builder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, Title);
// builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM, bitmap1);
builder.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, bitmap1);
mediaSession.setMetadata(builder.build());
}
Now the NOTIFICATION....
public void BuildNotificatio(){
//============Getting Bitmap for setting large icon==========//
Bitmap bitmap;
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(PATH.get(position));
byte[] data = mmr.getEmbeddedPicture();
if (data != null) {
bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
} else {
bitmap=BitmapFactory.decodeResource(getResources(),
R.drawable.example_picture);
}
//==========================================================//
if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O) {
Notification builder = new NotificationCompat.Builder(this,
notification.CHANNEL_ID_ONE)
.setShowWhen(false)
.setStyle(new
android.support.v4.media.app.NotificationCompat.MediaStyle()
.setMediaSession(mediaSession.getSessionToken())
.setShowActionsInCompactView(0,1,2)
.setShowCancelButton(true))
.setSmallIcon(android.R.drawable.stat_sys_headset)
.setColor(getResources().getColor(R.color.colorAccent))
.setContentTitle(Title)
.setContentText(Artist)
.setLargeIcon(bitmap)
.addAction(android.R.drawable.ic_media_previous,"",backIntent)
.addAction(index,"",playIntent)
.addAction(android.R.drawable.ic_media_next,"",nextIntent)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.build();
startForeground(Notification_ID,builder);
}else{
Notification notification = new NotificationCompat.Builder(this)
.setStyle(new
android.support.v4.media.app.NotificationCompat.MediaStyle()
.setMediaSession(mediaSession.getSessionToken()))
.setShowWhen(false)
.setSmallIcon(android.R.drawable.stat_sys_headset)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setLargeIcon(bitmap)
.build();
startForeground(Notification_ID,notification);
}
}
All things are working fine like controls on lock screen etc, But the only problem is not changing the lock screen wallpaper of device
How can I achieve this... OR
How can I check the bitmap dp size or scaled Down Bitmap to required dp size
Feel Free To Ask For More Info
来源:https://stackoverflow.com/questions/54742921/why-mediasession-not-changing-the-lock-screen-background-may-be-bitmap-size-pro