I\'m trying to create a notification media controller in my app using the code below which is working fine on all devices expect Huawei P8 Lite with An
I had the same issue and the root cause was not able to setStyle, it was only giving this exception in Huawei P8 Lite, not on other devices.
So, what i had to do was check if current device is android version 5.0 and its manufacturer is Huawei and remove the setStyle property. please check below code
boolean isLollipopHuawei = (android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1 ||
android.os.Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) && Build.MANUFACTURER.equalsIgnoreCase("HUAWEI");
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT || Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP_MR1 || Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
if (isLollipopHuawei) {
return builder
.addAction(generateAction(android.R.drawable.ic_media_previous, "Previous", Constants.ACTION_PREVIOUS))
.addAction(action)
.addAction(generateAction(android.R.drawable.ic_media_next, "Next", Constants.ACTION_NEXT))
.setSmallIcon(R.mipmap.vpicon_grayscale)
.setContentTitle(getSongDataHelper().getTitle())
.setContentIntent(pendingIntent)
.setContentText(getSongDataHelper().getAlbum())
.setLargeIcon(getSongDataHelper().getAlbumArt())
//.setColor(color)
/* .setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0, 1, 2)
.setMediaSession(mMediaSession.getSessionToken()))*/
.build();
} else {
return builder
.addAction(generateAction(android.R.drawable.ic_media_previous, "Previous", Constants.ACTION_PREVIOUS))
.addAction(action)
.addAction(generateAction(android.R.drawable.ic_media_next, "Next", Constants.ACTION_NEXT))
.setSmallIcon(R.mipmap.vpicon_grayscale)
.setContentTitle(getSongDataHelper().getTitle())
.setContentIntent(pendingIntent)
.setContentText(getSongDataHelper().getAlbum())
.setLargeIcon(getSongDataHelper().getAlbumArt())
//.setColor(color)
.setStyle(new androidx.media.app.NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0, 1, 2)
.setMediaSession(mMediaSession.getSessionToken()))
.build();
}
}