android - React-native:在 Android 中允许音频的权限

标签 android react-native push-notification permissions android-permissions

如何在不进入手机设置的情况下授予允许在 Android 应用程序中使用音频的权限? 当收到通知但没有通知声音时,我正在使用带有 firebase 云消息的推送通知。如果我转到手机设置并打开应用程序通知,然后会收到音频通知

enter image description here

最佳答案

尝试使用 react-native-push-notification npm 包创建自定义通知 channel

根据您的要求创建一个 android 通知 channel ,例如声音、通知重要性等。

例如:

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 中添加通知 channel ID 名称以接收来自 firebase 云消息传递的通知。

喜欢:

// <projectRoot>/firebase.json
{
  "react-native": {
    "messaging_android_notification_channel_id": "channel-id"
  }
}

查看官方文档了解更多信息。

https://github.com/zo0r/react-native-push-notification

关于android - React-native:在 Android 中允许音频的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66344270/

相关文章:

java - 如何设置推送通知的图标

android - 在没有 ActionBarSherlock 的情况下在 Actionbar ShareActionProvider 上设置自定义共享图标

android - 屏幕密度为 440 dpi 的设备与在 Google Play 上发布的应用不兼容

javascript - 如何为每个 createTableViewRow 添加标签并将所有内容居中?

android - DialogFragment 中的 ListView 在 Android 4.0 中被禁用

react-native - TabNavigator 中是否可以使用 StackNavigator?

react-native - 将数据传递给 React Native 中的组件?

iphone - 处理发送推送通知错误的方法

javascript - 处理多个 Promise 以获得多个文件下载的总进度

android - 如何检测应用程序是使用应用程序图标点击打开还是从通知点击打开?