Android 8.0之后Notification弹出方式

早期的版本直接启动

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);
复制代码

转载于:https://juejin.im/post/5ca465786fb9a05e396a459d

你可能感兴趣的:(Android 8.0之后Notification弹出方式)