Android开发安卓10不显示通知栏Notification不显示

 Android8.0以上得加channelId

Intent intent = new Intent(SplashActivity.this,ChatActivity.class);
                PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
                Notification notification;
                Notification.Builder builder;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    builder=new Notification.Builder(this,"5996773");
                }else {
                    builder=new Notification.Builder(this);
                }
                //设置标题
                builder.setContentTitle("设置标题");
                //设置内容
                builder.setContentText("内容是............");
                //设置状态栏显示的图标,建议图标颜色透明
                builder.setSmallIcon(R.mipmap.ic_launcher);
                // 设置通知灯光(LIGHTS)、铃声(SOUND)、震动(VIBRATE)、(ALL 表示都设置)
                builder.setDefaults(Notification.DEFAULT_ALL);
                //灯光三个参数,颜色(argb)、亮时间(毫秒)、暗时间(毫秒),灯光与设备有关
                builder.setLights(Color.RED, 200, 200);
                // 铃声,传入铃声的 Uri(可以本地或网上)我这没有铃声就不传了
                builder.setSound(Uri.parse("")) ;
                // 震动,传入一个 long 型数组,表示 停、震、停、震 ... (毫秒)
                builder.setVibrate(new long[]{0, 200, 200, 200, 200, 200});
                // 通知栏点击后自动消失
                builder.setAutoCancel(true);
                // 简单通知栏设置 Intent
                builder.setContentIntent(pendingIntent);
                builder.setPriority(Notification.PRIORITY_HIGH);

                //设置下拉之后显示的图片
                builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    NotificationChannel channel = new NotificationChannel("5996773", "安卓10a", NotificationManager.IMPORTANCE_DEFAULT);
                    channel.enableLights(true);//是否在桌面icon右上角展示小红点
                    channel.setLightColor(Color.GREEN);//小红点颜色
                    channel.setShowBadge(false); //是否在久按桌面图标时显示此渠道的通知
                    mNManager.createNotificationChannel(channel);
                }
                notification=builder.build();
                mNManager.notify(1,notification);

 

你可能感兴趣的:(Android开发安卓10不显示通知栏Notification不显示)