Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native: permission to allow audio in Android

How do I give permission to allow audio in Android app without going to settings of phone? I am using push notification with firebase cloud message, when there is received notification but no notification sound. If I go to phone's settings and turn on notifications for app then get an audio notification

enter image description here

like image 939
Mars Avatar asked Feb 02 '26 02:02

Mars


1 Answers

Have a try by creating a custom notification channel using the react-native-push-notification npm package.

Create an android notification channel with your requirements like sound, notification importance, etc.

For example:

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.
  );

and add the notification channel-id name in the firebase.json to receive notification from firebase cloud messaging.

Like:

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

Check out the official docs for more information.

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

like image 85
Jignesh Mayani Avatar answered Feb 03 '26 16:02

Jignesh Mayani