android studio提示java_服务发送的通知不会显示[Android Studio/Java]

匿名用户

像下面这样创建频道,Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

AudioAttributes audioAttributes = new AudioAttributes.Builder()

.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)

.setUsage(AudioAttributes.USAGE_NOTIFICATION)

.build();

String characterSequence = "Message Alert";

NotificationChannel channel = new NotificationChannel(channelId,

characterSequence,NotificationManager.IMPORTANCE_DEFAULT);

channel.setSound(soundUri,audioAttributes );

NotificationManager manager = (NotificationManager)

this.getSystemService(Context.NOTIFICATION_SERVICE);

manager.createNotificationChannel(channel);

}

您需要像下面这样在这里传递频道id,NotificationCompat.Builder builder= new NotificationCompat.Builder(APITest2.this,channelId)

另请参阅https://developer.android.com/training/notify-user/channels

如果您需要显示heads up通知,那么您需要将通知通道中的重要性级别设置为importance_high。 并且需要在notification builder中设置优先级,如下所示。setPriority(NotificationCompat.PRIORITY_HIGH);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值