3 回答

TA贡献1851条经验 获得超5个赞
尝试使用react-native-immediate-phone-call
import RNImmediatePhoneCall from 'react-native-immediate-phone-call'; ... RNImmediatePhoneCall.immediatePhoneCall('0123456789'); ...

TA贡献1871条经验 获得超8个赞
我已经看到了很多关于这方面的东西,所以我终于得到了解决方案。所以解决方案是建立一个黑白桥接本机和java,这样你就可以调用java功能来使用此代码进行直接调用。 String dial = "tel:" + phn_number; reactcontext.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));
首先检查权限。如果未授予,请先请求许可,然后拨打号码。
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)));
}
确保您在清单中添加权限,例如。
<uses-permission android:name="android.permission.CALL_PHONE" />

TA贡献1735条经验 获得超5个赞
您可以使用react-native-send-intent库
如果您需要直接使用电话呼叫,那么在 AndroidManifest.xml 文件中请求许可非常重要。您可以添加可选的第二个参数,以修复默认的手机应用程序。
<uses-permission android:name="android.permission.CALL_PHONE" />
如何使用
var SendIntentAndroid = require("react-native-send-intent");
SendIntentAndroid.sendPhoneCall("+1 234567 8900", true);
示例代码
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>
)
您可以在 onPress 事件中使用上述函数
添加回答
举报