
我已经设法在较旧的API中使用通知,但不是Oreo.创建通知会导致我的应用程序仍能正常工作(logcat中没有消息),但是当Activity运行时,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; } }解决方法:
从mipmap切换到drawable图标.有关更多信息,请参见this issue
总结以上是内存溢出为你收集整理的java – Android Oreo Notification崩溃系统UI全部内容,希望文章能够帮你解决java – Android Oreo Notification崩溃系统UI所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)