README
⚠️ Currently only available for android.
react-native-phonecall-control
A react-native module that allows you to make a call and (soon) handle certain other options about the call.
Partially inspired by @wumke 's react-native-immediate-phone-call.
Installation
npm install react-native-phonecall-control
or
yarn add react-native-phonecall-control
Configuration
Android
In order to make the phone call you'll have to add the CALL_PHONE
permission to AndroidManifest.xml
.
ℹ️ Note: If you plan on using speakerphone as well, you will also need to add
MODIFY_AUDIO_SETTINGS
permission toAndroidManifest.xml
.
In ./android/app/src/main/java/MainActivity.java
:
import androidx.annotation.RequiresApi;
import android.os.Build;
import android.content.Intent;
import com.reactnativephonecallcontrol.PhonecallControlPackage;
// ...
// then inside your project's class:
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
PhonecallControlPackage.onRequestPermissionsResult(requestCode, permissions, grantResults);
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
PhonecallControlPackage.onActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
}
iOS
Not yet implemented.
Usage
import React from 'react';
import { Button } from 'react-native';
import PhonecallControl from 'react-native-phonecall-control';
// ...
export const Component = () => {
// ...
useEffect(() => {
// Not required, start call requests permission on its own as well
PhonecallControl.requestPermission();
});
const handleCallClick = async() => {
const phoneNum = '5555555555'
PhonecallControl.startCall(phoneNum, { minimize: true });
// ...
}
// ...
return (
// ...
<Button title="CALL" onPress={handleCallClick} />
// ...
)
}
API
import PhonecallControl from 'react-native-phonecall-control';
or
import { requestPermission, startCall } from 'react-native-phonecall-control';
Methods
PhonecallControl.requestPermission()
Gives the user a pop-up requesting CALL_PHONE
permission.
PhonecallControl.startCall(number, options)
Requests permission (if needed) then starts a phone call (if granted the permission).
Arguments
- number (string) — The phone number to call.
- options (object) — A map of options:
- enableSpeaker (boolean) — Specifies whether the call will start on speaker. Defaults to
false
unlessminimize === true
. Minimized calls will always start on speaker. - minimize (boolean) — Specifies whether the call will be minimized. Defaults to
false
.
- enableSpeaker (boolean) — Specifies whether the call will start on speaker. Defaults to
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.