安卓奥利奥通知崩溃系统UI

我已经设法让通知在较旧的API中工作,但不是Oreo。创建通知会导致我的应用仍然正常工作(logcat 中没有消息),但是当活动运行时,SystemUI 会在无休止的循环中崩溃并重新启动。是 systemui 进程的 logcat 中的错误:

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。

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;

    } }

答案 1

从 切换到 图标。有关详细信息,请参阅此问题mipmapdrawable


答案 2

该问题与Android O中新的自适应图标有关。

要解决此问题,只需将所有自适应图标替换为经典图标即可。无论是 mipmap 还是可绘制

一些参考: 链接 1 链接 2