android - React-native:允许在 Android 中使用音频的权限
问题描述
如何在不进入手机设置的情况下授予允许在 Android 应用中使用音频的权限?当收到通知但没有通知声音时,我正在使用带有 firebase 云消息的推送通知。如果我转到手机设置并打开应用程序通知,然后会收到音频通知
解决方案
尝试使用react-native-push-notification npm 包创建自定义通知通道。
根据您的要求(如声音、通知重要性等)创建一个 android 通知通道。
例如:
PushNotification.createChannel(
{
channelId: "channel-id", // (required)
channelName: "My channel", // (required)
channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
playSound: false, // (optional) default: true
soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
importance: 4, // (optional) default: 4. Int value of the Android notification importance
vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
},
(created) => console.log(`createChannel returned '${created}'`) // (optional) callback returns whether the channel was created, false means it already existed.
);
并在 firebase.json 中添加通知通道 ID 名称以接收来自 firebase 云消息传递的通知。
喜欢:
// <projectRoot>/firebase.json
{
"react-native": {
"messaging_android_notification_channel_id": "channel-id"
}
}
查看官方文档了解更多信息。
推荐阅读
- c# - Guid 和 NativeGuid 抛出 COMException
- git - 当我将 GitHub 集成到我的 Android Studio 3.3.1 项目时,哪种方式是正确的?
- python - 比较两个numpy数组的对象ID
- brute-force - 如何保护 OTP(一次性密码)免受暴力攻击?
- json - JQ,如何根据条件计算?
- node.js - 如何解决 Passport-jwt 令牌未经授权的错误?
- elasticsearch - Fluentd Elasticsearch Kibana 记录动态索引 GEOPOINT 映射
- android - TwitterSession 不能为空
- php - Cloud Firestore API 未启用,尝试从 PHP 访问时出现 FAILED_PRECONDITION
- ios - 无法在 Xcode 中找到设备支持文件