android oreo ui,Android Oreo通知导致系统UI崩溃

我设法使通知在较旧的API中起作用,但在Oreo中不起作用。创建通知会导致我的应用程序仍然可以正常运行(logcat中没有消息),但是在Activity运行时,SystemUI崩溃并以无休止的周期重启。这是systemcat进程的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;

} }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值