android.app.RemoteServiceExcepti

2024-01-28  本文已影响0人  牛年大吉2021

问题描述:
android.app.RemoteServiceException$CannotPostForegroundServiceNotificationException: Bad notification for startForeground。
解决方案:
8.0以上 通知 需要创建通知通道
/**
* 创建通知通道
* @param channelId
* @param channelName
* @return
*/
@RequiresApi(Build.VERSION_CODES.O)
private String createNotificationChannel(String channelId, String channelName){
NotificationChannel chan = new NotificationChannel(channelId,
channelName, NotificationManager.IMPORTANCE_NONE);
chan.setLightColor(Color.BLUE);
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
NotificationManager service = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
service.createNotificationChannel(chan);
return channelId;
}

上一篇下一篇

猜你喜欢

热点阅读