startForeground不再显示通知

时间:2018-01-20 18:33:48

标签: java android service notifications android-7.0-nougat

在我的前台服务中,启动服务的代码如下:

 notificationBuilder = new NotificationCompat.Builder(this, channelId)
                .setContentIntent(contentIntent)
                .setSmallIcon(R.mipmap.ic_launcher)  // the status icon
                .setWhen(System.currentTimeMillis())  // the time stamp
                .setCustomContentView(getSmallContentView())
                .setCustomBigContentView(getBigContentView())
                .setAutoCancel(false)
                .setOnlyAlertOnce(true)
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .setOngoing(true);
        if (Build.VERSION_CODES.O <= Build.VERSION.SDK_INT) {
            NotificationChannel notificationChannel = new NotificationChannel(channelId, channelId, NotificationManager.IMPORTANCE_DEFAULT);
            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.createNotificationChannel(notificationChannel);
        }
        Notification notification = notificationBuilder.build();
        // Send the notification.
        startForeground(notificationId, notification);

致电stopForeground(true),之后调用startForeground(id,notification)并未在前台服务中再次显示通知。

任何帮助将不胜感激。

0 个答案:

没有答案