Skip to content

SolankiYogesh/react-native-audio-focus

Repository files navigation

AudioFocus

This package provides functionality to handle audio focus changes and incoming calls in a React Native application on Android.

Installation

To install this package, follow these steps:

  1. Install the package using npm or Yarn:

    npm install react-native-audio-focus

    or

    yarn add react-native-audio-focus
  2. Link the native module:

    react-native link react-native-audio-focus

Usage

To use the AudioFocus module in your React Native code, follow these steps:

  1. Import the module:

    import AudioFocus from 'react-native-audio-focus';
  2. Add listeners to handle audio focus changes and incoming calls:

    // Add listener for audio focus changes
    AudioFocus.addListener('onAudioFocusChange', (focusChange) => {
      // Handle audio focus change event
    });
    
    // Add listener for incoming calls
    AudioFocus.addListener('onIncomingCall', () => {
      // Handle incoming call event
    });
  3. Remove listeners when they are no longer needed:

    AudioFocus.removeListener();

Permissions

Make sure to add the necessary permissions to your AndroidManifest.xml file to handle incoming calls:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

Troubleshooting

If you encounter any issues or errors while using this package, please refer to the GitHub repository for further information and troubleshooting steps.

License

This package is released under the MIT License.

Contributing

Contributions to this package are welcome! If you find any bugs or want to suggest new features, please open an issue or submit a pull request on the GitHub repository.

Acknowledgments

This package is inspired by the React Native Audio Focus package.

Contact

For any inquiries or questions, please contact [email protected].