private void setNotification() throws FileNotFoundException {
String ChannelId = "渠道ID";
NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this); /*1.系统通知管理*/
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { /*2.安卓8 NotificationChannel*/
NotificationChannel channel = new NotificationChannel(ChannelId,"渠道名称", NotificationManager.IMPORTANCE_HIGH/*重要等级*/);
channel.setDescription("设置渠道描述");
channel.setBypassDnd(true); /*是否绕过请勿打扰模式*/
channel.setShowBadge(false); /*是否显示桌面Launcher的消息角标*/
channel.setSound(null, null); /*通知出现时声音,默认通知是有声音的*/
channel.enableLights(false); /*通知出现时的闪灯(如果 android 设备支持的话)*/
channel.setLightColor(Color.RED); /*闪灯颜色*/
channel.enableVibration(false); /*是否启用震动(如果 android 设备支持的话)*/
channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); /*震动模式*/
managerCompat.createNotificationChannel(channel); /*传给系统通知管理*/
}
RemoteViews views = new RemoteViews(getPackageName(),R.layout.notice_audio); /*3.布局文件*/
views.setTextViewText(R.id.t1_6,listAudioModel.get(B).getSong()); /*绑定控件id 赋值*/
views.setTextViewText(R.id.t2_6,listAudioModel.get(B).getSinger());
if (ContentResolver_.getAlbumBitmap(this,listAudioModel.get(B).getAlbumId()) != null){
views.setImageViewBitmap(R.id.i1_6,ContentResolver_.getAlbumBitmap(this,listAudioModel.get(B).getAlbumId()));
}else { views.setImageViewResource(R.id.i1_6,R.drawable.ic_music); }
views.setImageViewResource(R.id.i2_6,R.drawable.ic_previoussong);
views.setImageViewResource(R.id.i3_6,R.drawable.ic_zanting);
views.setImageViewResource(R.id.i4_6,R.drawable.ic_futuresong);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,ChannelId); /*4.通知*/
builder.setSmallIcon(R.drawable.ic_music/*通知图标*/)
// .setContentTitle("通知标题").setContentText("通知内容").setWhen(/*设置通知时间*/System.currentTimeMillis())
.setOngoing(/*通知右滑无法删除*/true)
// .setContent(/*绑定布局文件*/views) /*最高高度64 超出则显示不全*/
.setCustomBigContentView(/*绑定布局文件*/views); /*最高高度256 超出则显示不全*/
Notification notification = builder.build(); /*5.创建通知*/
boolean isEnabled = managerCompat.areNotificationsEnabled(); /*检查通知权限 返回true:开*/
managerCompat.notify(1,notification); /*6.系统通知管理 通知*/
}
通知栏:Notification
猜你喜欢
转载自blog.csdn.net/qq_34411066/article/details/105455586
今日推荐
周排行