通知栏

@RequiresApi(api = Build.VERSION_CODES.O)
private void showNotification(){
NotificationChannel notificationChannel=new NotificationChannel("channelId","channelName",NotificationManager.IMPORTANCE_HIGH);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new NotificationCompat.Builder(this).setContentText(getString(R.string.app_name))
.setSmallIcon(R.mipmap.ic_launcher).setWhen(System.currentTimeMillis()).setContentTitle(getString(R.string.app_name))
.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
.setChannelId("channelId").setAutoCancel(false).build();
manager.createNotificationChannel(notificationChannel);
manager.notify(1001,notification);
}
posted @ 2021-03-12 09:58  Prime_T  阅读(350)  评论(0编辑  收藏  举报