android - 带有 Xamrin Forms 的 Firebase 自定义声音通知适用于 IOS,但在应用未运行时不适用于 android
问题描述
我到处搜索并尝试了许多没有运气的解决方案。我正在使用 API 向我的应用程序(Android / IOS)发送通知,其中包含已包含在我的应用程序文件中的自定义声音文件。即使应用程序关闭,声音也适用于 IOS,但在应用程序在后台运行之前,它不适用于 Android。这是我使用的 JSON
{
to = deviceId,
priority = "high",
content_available = true,
notification = new
{
body = englishMessage,
title = title,
badge = 1,
content_available = true
},
android = new
{
ttl="86400s",
priority= "high",
notification = new
{
sound = SoundFileName,
},
},
apns = new
{
payload = new
{
aps = new
{
sound = SoundFileName,
content_available = true,
badge = 1,
},
},
customKey = "test app",
}
}
解决方案
当您的应用程序处于前台时,通知是由您手动生成的,这意味着您需要手动将此声音添加到通知中,所以您所做的就像
var soundUri = Android.Net.Uri.Parse(pathToPushSound);
然后在通知管理器中添加如下方法
var notiManager= Notification.Builder(context)
.SetSound(soundUri) ...
推荐阅读
- r - 如何在 markdown / knitr 中的消息中换行?
- excel - hlookup vlookup 返回多个值
- python - 使用 Twisted 像服务一样运行 python 脚本
- python - 在 groupby 之后的多索引数据帧 .columns.levels[1] 给出整个数据帧的列
- java - (JOOQ)当我尝试编译项目时,Mysql 出现连接错误
- .net - MVVM-Light EventToCommand 风格
- flask - 在 jinja2 和 js 之间共享设计数据
- swift - 如何定义节点的区域以使其成为按钮
- python - 8x8 矩阵上的陀螺仪动画
- f# - 在 JetBrains Rider 中,如何显示光标下符号的类型信息?