小编Meh*_*oob的帖子

Android Oreo无法播放自定义声音以进行通知

我正在尝试为API> 26的通知添加自定义声音.下面是代码

NotificationChannel notificationChannel = new NotificationChannel("channel id","channel name",NotificationManager.IMPORTANCE_HIGH);
mNotificationManager.createNotificationChannel(notificationChannel);
AudioAttributes audioAttributes = new AudioAttributes.Builder()
                    .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                    .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                    .build();
notificationChannel.setSound(Uri.parse("android.resource://" + BuildConfig.APPLICATION_ID + "/raw/beep"),audioAttributes);
Run Code Online (Sandbox Code Playgroud)

这里的问题是它播放设备的默认钢琴声而不是播放来自资产的哔声.我不被允许使用铃声管理器但是常识统计数据通知声音应该是指定的而不是默认值.

它适用于API <= 26

android android-notifications android-8.0-oreo android-8.1-oreo

9
推荐指数
1
解决办法
6575
查看次数

在Android中发送本地通知

我想在android中为我的应用程序使用本地通知.如果应用程序未打开24小时,则发送本地通知.任何人都可以告诉我应该怎么做.

notifications android

7
推荐指数
1
解决办法
2万
查看次数