安卓:8.0发送通知

前言:
这个写的很随意,通知有很多的样式,自己复习用的不喜勿喷!

AS 官网:
https://developer.android.google.cn/

//创建NotificationChannel 的id(前俩个参数自己随便写)
                NotificationChannel notificationChannel = new NotificationChannel("1","notify", NotificationManager.IMPORTANCE_HIGH);
                //开启他的服务
                NotificationManager  manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                //声音
                notificationChannel.setSound(null,null);
                //创建通知
                manager.createNotificationChannel(notificationChannel);
                builder = new Notification.Builder(this);
                builder.setChannelId("1");
                //小图像
                builder.setSmallIcon(R.mipmap.ic_launcher);
                //标题
                builder.setContentTitle("aaaaa");
                //什么时候发送通知
                builder.setWhen(System.currentTimeMillis());
                //自动取消
                builder.setAutoCancel(true);
                //开启
                manager.notify(123,builder.build());

你可能感兴趣的:(安卓:8.0发送通知)