NotificationChannel channel = new NotificationChannel( id: "com.xxx.xx",
"XxxService", NotificationManager.IMPORTANCE_NONE);
//channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
channel.setSound( sound: null, audioAttributes: null);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.MOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
NotificationCompat.Builder notiBuidler = new NotificationCompat.Builder(context: this, channelld: "com.xxx.xx");
//设置为CATEGORY_CALL同时需要设置Icon和Title才会没有声音,并且不会在通知中心显示通知
Notification notification = notiBuidler.set0ngoing(true)
.setSound(null)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentTitle("XxxService")
.setContentText("XxxService")
.setPriority(NotificationCompat.PRIORITY_LOW)
.setCategory(Notification.CATEGORY_CALL)
.build();
startForeground( id: 1, notification);
android 将服务设置为前台服务
最新推荐文章于 2024-04-04 16:12:51 发布