为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕慕森 2023-10-20 15:07:25
我正在使用拨号应用程序,应用程序可以简单地自动从列表中一一拨打号码。这里的主要问题是,我不希望每次触发呼叫时都显示拨号器。简而言之,我如何直接在应用程序中拨打号码,而无需在 Android 平台的 React Native 中打开拨号器。
查看完整描述

3 回答

?
江户川乱折腾

TA贡献1851条经验 获得超5个赞

尝试使用react-native-immediate-phone-call

import RNImmediatePhoneCall from 'react-native-immediate-phone-call';
...
RNImmediatePhoneCall.immediatePhoneCall('0123456789');
...


查看完整回答
反对 回复 2023-10-20
?
ITMISS

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" />


查看完整回答
反对 回复 2023-10-20
?
喵喔喔

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 事件中使用上述函数


查看完整回答
反对 回复 2023-10-20
  • 3 回答
  • 0 关注
  • 111 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信