短视频系统,通知栏的基本使用已成为APP的基础配套功能了,有新的消息推送到通知栏,点击通知栏,进入指定的Activity,今天我们来分享相关的代码
NotificationManager notificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE) ; Intent intent=new Intent(this,Second.class); Context context=this; PendingIntent pendingIntent=PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT); CharSequence name; Button v1 = (Button) v; // 传入参数:通道ID,通道名字,通道优先级(类似曾经的 builder.setPriority()) NotificationChannel channel=new NotificationChannel(0, "name", 5); notificationManager.createNotificationChannel(channel); NotificationCompat.Builder mb=new NotificationCompat.Builder(this,"1"); mb.setContentTitle("测试信息") .setContentText("测试信息内容") .setSmallIcon(R.mipmap.logo) .setTicker("收到一条消息").setWhen(System.currentTimeMillis()) .setContentIntent(pendingIntent); notificationManager.notify(1,mb.build()); // 配置通知渠道的属性 channel.setDescription(description); // 设置通知出现时声音,默认通知是有声音的 channel.setSound(null, null); // 设置通知出现时的闪灯(如果 android 设备支持的话) channel.enableLights(true); channel.setLightColor(Color.RED); // 设置通知出现时的震动(如果 android 设备支持的话) channel.enableVibration(true); channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); //最后在 notificationManager 中创建该通知渠道 mNotificationManager.createNotificationChannel(channel)以上就是短视频系统,通知栏的基本使用的相关代码, 更多内容欢迎关注之后的文章