安卓通知声音

编程入门 行业动态 更新时间:2024-10-19 12:36:07
本文介绍了安卓通知声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用了较新的 NotificationCompat 构建器,但无法收到通知以发出声音.它会振动并闪烁灯光.android 文档说要设置我已经完成的样式:

I've used the newer NotificationCompat builder and I can't get the notification to make a sound. It will vibrate and flash the light. The android documentation says to set a style which I've done with:

builder.setStyle(new NotificationCompat.InboxStyle());

但是没有声音?

完整代码:

NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher) .setContentTitle("Notifications Example") .setContentText("This is a test notification"); Intent notificationIntent = new Intent(this, MenuScreen.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); builder.setAutoCancel(true); builder.setLights(Color.BLUE, 500, 500); long[] pattern = {500,500,500,500,500,500,500,500,500}; builder.setVibrate(pattern); builder.setStyle(new NotificationCompat.InboxStyle()); // Add as notification NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(1, builder.build());

推荐答案

我之前的代码缺少什么:

What was missing from my previous code:

Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); builder.setSound(alarmSound);

更多推荐

安卓通知声音

本文发布于:2023-11-27 08:03:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637199.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:声音   通知

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!