Reputation: 29
I am working with dialing application where application can simply automatically call numbers one by one from the list . The main issue here is ,I don't want the dialer shown every time when call is triggered. In Short how can I directly call a number in app without opening dialer in react native for android platform.
Upvotes: 0
Views: 3395
Reputation: 4801
you can use react-native-send-intent library
It's very important to ask for permission in your AndroidManifest.xml file if you need to use Phone Calls directly. You can add an optional second parameter, to fix the default phone app.
<uses-permission android:name="android.permission.CALL_PHONE" />
How to Use
var SendIntentAndroid = require("react-native-send-intent");
SendIntentAndroid.sendPhoneCall("+1 234567 8900", true);
Sample Code
var SendIntentAndroid = require("react-native-send-intent");
const InitiateCall = async () => {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.CALL_PHONE,
{
title: "App Needs Permission",
message:
`Myapp needs phone call permission to dial direclty `,
buttonNegative: "Disagree",
buttonPositive: "Agree"
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
SendIntentAndroid.sendPhoneCall("+1 234567 8900", true);
console.log("You dialed directly");
} else {
console.log("No permission");
}
}
return (
<TouchableOpacity onPress={() => InitiateCall ()}>
<YourComponent/>
</TouchableOpacity>
)
You can use the above function in onPress event
Upvotes: 0
Reputation: 29
I have seen to much stuff about that so I finally get the solution .So the solution is to make a bridge b/w react native and java ,so that u can call java functionality to make a direct call using this code.
String dial = "tel:" + phn_number; reactcontext.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
first check permission. If it is not granted then first ask for the permission and then dial number.
if (ContextCompat.checkSelfPermission(reactcontext,
Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(reactcontext.getCurrentActivity(),
new String[]{Manifest.permission.CALL_PHONE}, REQUEST_CALL);
} else {
String dial = "tel:" + phn_number;
reactcontext.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
}
Make sure u add permission in manifest like.
<uses-permission android:name="android.permission.CALL_PHONE" />
Upvotes: 0
Reputation: 6967
Try using react-native-immediate-phone-call
import RNImmediatePhoneCall from 'react-native-immediate-phone-call';
...
RNImmediatePhoneCall.immediatePhoneCall('0123456789');
...
Upvotes: 1