React Native Call Detection
This package helps to detect different call states like Incoming, Disconnected, Dialing and Connected for iOS. For android, this package will give following states, Offhook, Incoming, Disconnected and Missed. In the case of Incoming for android, the package will also provide with the incoming phone number.
Installation
Add the package to your react-native project in the following way
Link the current package to your react native project
For Android:-
Just Verify that the following changes are present in the corresponding files
- In
MainApplication.java
- In
android/settings.gradle
:
- In
android/app/build.gradle
:
Usage
There are different hooks that you may get depending on the platform. Since for android you could also request the package to provide you with phone number of the caller, you will have to provide the necessary request message and the corresponding error callback. The package will request for READ_PHONE_STATE
permission in android.
Its really easy to setup the package. Have a look at the following code snippet
Dont forget to call dispose
when you don't intend to use call detection, as it will avoid memory leakages.
Example project can be used to test out the package. In the example project update the HomeComponent.js
with the phone number to call
Caveat
Since For android, there is no native support to detect call being disconnected, the callback with "Disconnected" event will be called only when the app comes in foreground.
How to run an example
-
Install
node
andwatchman
brew install node brew install watchman
-
yarn
Install
yarn
fromnpm
.npm i -g yarn
-
Xcode
Install it from the App Store.
-
React Native Debugger
This is an electron app that bundles react devtools, redux devtools and chrome devtools configured for use with react-native.
brew cask install react-native-debugger
-
Once you have done all the above steps, navigate to
CallDetectionExample
folder and runyarn
ornpm install
, it will fetch all the dependencies in thenode_modules
folder. -
Run the packager
npm start
-
Update the mobile number of your friend in
HomeComponent.js
-
To run the example on iOS from terminal type
react-native run-ios
(This will open the simulator, since simulator doesnt have the support for calling I will advice you to connect your iOS device and the follow the below procedure for running the app through xcode)or you can also run the app from xcode, for that, open
/CallDectionExample/ios/CallDetectionExample.xcodeproj
in xcode and run on the device. -
To run the example on android, connect any android device to your mac then follow the below steps
- Navigate to
android
folder(./CallDectionExample/android/) folder and then runadb reverse tcp:8081 tcp:8081
- Navigate back to example directory(CallDectionExample) and then run
react-native run-android
- Navigate to
For any problems and doubt raise an issue.