Caused by: java.lang.IllegalArgumentException: setShowActionsInCompactView: action 1 out of bounds (max 0)
fix
builder.setStyle(
new androidx.media.app.NotificationCompat.MediaStyle()
.setMediaSession(token)
.setShowActionsInCompactView(byState(state.getActions()))
private int[] byState(long actions) {
if(actions == (PlaybackStateCompat.ACTION_PLAY
| PlaybackStateCompat.ACTION_SKIP_TO_NEXT
| PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
| PlaybackStateCompat.ACTION_PAUSE)) {
return new int[]{0,1,2};
}
if(actions == (PlaybackStateCompat.ACTION_PLAY
| PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS
| PlaybackStateCompat.ACTION_PAUSE)) {
return new int[]{0,1};
}
if(actions == (PlaybackStateCompat.ACTION_PLAY
| PlaybackStateCompat.ACTION_SKIP_TO_NEXT
| PlaybackStateCompat.ACTION_PAUSE)) {
return new int[]{0,1};
}
if(actions == (PlaybackStateCompat.ACTION_PLAY
| PlaybackStateCompat.ACTION_PAUSE)) {
return new int[]{0};
}
return new int[0];
}
fun startSelf(context: Activity) {
val notificationIntent = Intent(context, context::class.java)
notificationIntent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
val pendingIntent: PendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0)
try {
pendingIntent.send()
} catch (e: PendingIntent.CanceledException) {
e.printStackTrace()
}
}