이전 API에서는 작동하지만 Oreo에서는 작동하지 않는 알림을 얻을 수있었습니다. 알림을 생성하면 내 응용 프로그램이 계속 정상적으로 작동하지만 (logcat에서는 메시지가 표시되지 않음), Activity가 실행되는 동안 SystemUI가 충돌하고 무한 순환으로 재부팅됩니다.Android Oreo 알림이 시스템 UI를 충돌 함
java.lang.IllegalArgumentException: width and height must be > 0
내 코드 :
private void showPlayingNotification() {
NotificationCompat.Builder builder = mNotificationUtils.getAndroidChannelNotification(this, "Play", mMediaSessionCompat);
if(builder == null) {
Log.i("Play Notification","No notification found!");
return;
}
mNotificationUtils.getManager().notify(101,builder.build());
}
은 내가 만든 MediaPlayerService의에서 onCreate에 mNotificationUtils을 초기화는 systemui 과정에 대한 로그 캣에서 오류가 발생합니다. 아이콘에 대한 drawable
에 mipmap
에서
public class NotificationUtils extends ContextWrapper {
private NotificationManager mManager;
public static final String AUDIO_CHANNEL_ID = "com.liftyourheads.dailyreadings.dailyReadingsAudio";
public static final String AUDIO_CHANNEL_NAME = "Daily Readings Audio Stream";
public NotificationUtils(Context base) {
super(base);
createChannels();
}
public void createChannels() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// create android channel
NotificationChannel dailyReadingsAudioChannel = new NotificationChannel(AUDIO_CHANNEL_ID,
AUDIO_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH);
getManager().createNotificationChannel(dailyReadingsAudioChannel);
}
}
public NotificationManager getManager() {
if (mManager == null) {
mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}
return mManager;
}
public NotificationCompat.Builder getAndroidChannelNotification(Context context, String action, MediaSessionCompat mediaSession) {
if (action.equals("Play")) {
return MediaStyleHelper.from(context, mediaSession)
.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_pause, "Pause", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE)))
.setStyle(
new android.support.v4.media.app.NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0)
.setMediaSession(mediaSession.getSessionToken()))
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText("Content Text")
.setContentTitle("Content Title")
.setChannelId(AUDIO_CHANNEL_ID);
} else if (action.equals("Pause")) {
return MediaStyleHelper.from(context, mediaSession)
.addAction(new NotificationCompat.Action(android.R.drawable.ic_media_play, "Play", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE)))
.setStyle(
new android.support.v4.media.app.NotificationCompat.MediaStyle()
.setShowActionsInCompactView(0)
.setMediaSession(mediaSession.getSessionToken()))
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText("Content Text")
.setContentTitle("Content Title")
.setChannelId(AUDIO_CHANNEL_ID);
}
return null;
} }
고마워요! 이것이 이유였습니다. –