如何在不打开 Android 拨号器的情况下直接拨打 React Native 中的号码

我正在使用拨号应用程序,应用程序可以简单地自动从列表中一一拨打号码。这里的主要问题是,我不希望每次触发呼叫时都显示拨号器。简而言之,我如何直接在应用程序中拨打号码,而无需在 Android 平台的 React Native 中打开拨号器。



慕慕森
浏览 204回答 3
3回答

江户川乱折腾

尝试使用react-native-immediate-phone-callimport RNImmediatePhoneCall from 'react-native-immediate-phone-call'; ... RNImmediatePhoneCall.immediatePhoneCall('0123456789'); ...

ITMISS

我已经看到了很多关于这方面的东西,所以我终于得到了解决方案。所以解决方案是建立一个黑白桥接本机和java,这样你就可以调用java功能来使用此代码进行直接调用。 String dial = "tel:" + phn_number;&nbsp; &nbsp;reactcontext.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));首先检查权限。如果未授予,请先请求许可,然后拨打号码。if (ContextCompat.checkSelfPermission(reactcontext,&nbsp; &nbsp; &nbsp; &nbsp; Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {&nbsp; &nbsp; ActivityCompat.requestPermissions(reactcontext.getCurrentActivity(),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new String[]{Manifest.permission.CALL_PHONE}, REQUEST_CALL);} else {&nbsp; &nbsp; String dial = "tel:" + phn_number;&nbsp; &nbsp; reactcontext.startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(dial)));}确保您在清单中添加权限,例如。<uses-permission android:name="android.permission.CALL_PHONE" />

喵喔喔

您可以使用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 事件中使用上述函数
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript