Name: react-native-call-detection
Owner: OK GROW!
Description: react-native package to detect call states
Created: 2018-03-07 20:04:57.0
Updated: 2018-03-14 18:35:46.0
Pushed: 2018-03-14 18:35:45.0
Homepage: null
Size: 182122
Language: Java
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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.
Add the package to your react-native project in the following way
add react-native-call-detection
Link the current package to your react native project
t-native link react-native-call-detection
Just Verify that the following changes are present in the corresponding files
MainApplication.java
port com.pritesh.calldetection.CallDetectionManager;
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new CallDetectionManager(MainApplication.this)
);
}
android/settings.gradle
:
ude ':app'
clude ':react-native-call-detection'
oject(':react-native-call-detection').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-call-detection/android')
android/app/build.gradle
:ndencies {
...
compile "com.facebook.react:react-native:+" // From node_modules
compile project(':react-native-call-detection')
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
rt CallDetectorManager from 'react-native-call-detection'
tListenerTapped() {
this.callDetector = new CallDetectorManager((event)=> {
// For iOS event will be either "Connected",
// "Disconnected","Dialing" and "Incoming"
// For Android event will be either "Offhook",
// "Disconnected", "Incoming" or "Missed"
if (event === 'Disconnected') {
// Do something call got disconnected
}
else if (event === 'Connected') {
// Do something call got connected
// This clause will only be executed for iOS
}
else if (event === 'Incoming') {
// Do something call got incoming
}
else if (event === 'Dialing') {
// Do something call got dialing
// This clause will only be executed for iOS
}
else if (event === 'Offhook') {
//Device call state: Off-hook.
// At least one call exists that is dialing,
// active, or on hold,
// and no calls are ringing or waiting.
// This clause will only be executed for Android
}
else if (event === 'Missed') {
// Do something call got missed
// This clause will only be executed for Android
}
e, // if you want to read the phone number of the incoming call [ANDROID], otherwise false
{}, // callback if your permission got denied [ANDROID] [only if you want to read incoming number] default: console.error
e: 'Phone State Permission',
age: 'This app needs access to your phone state in order to react and/or to adapt to incoming calls.'
a custom permission request message to explain to your user, why you need the permission [recommended] - this is the default one
ListenerTapped() {
this.callDetector && this.callDetector.dispose();
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
llFriendTapped() {
Add the telephone num to call
Linking.openURL('tel:5555555555')
.catch(err => {
console.log(err)
});
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.
Install node
and watchman
install node
install watchman
yarn
Install yarn
from npm
.
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 run yarn
or npm install
, it will fetch all the dependencies in the node_modules
folder.
Run the packager
npm start
Update the mobile number of your friend in HomeComponent.js
lFriendTapped() {
Add the telephone number
Linking.openURL('tel:5555555555')
atch(err => {
console.log(err)
;
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
android
folder(./CallDectionExample/android/) folder and then run adb reverse tcp:8081 tcp:8081
react-native run-android
For any problems and doubt raise an issue.