早期的版本直接启动
startForeground(NOTIFICATION_ID, new Notification());
复制代码
8.0之后
// 26之后需要channelId
NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID_STRING, "APP", NotificationManager.IMPORTANCE_HIGH);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(mChannel);
Notification notification = new Notification.Builder(getApplicationContext(), CHANNEL_ID_STRING).build();
startForeground(NOTIFICATION_ID, notification);
复制代码