【问题标题】:how can I directly call a number in react native without opening dialer for android如何在不打开安卓拨号器的情况下直接拨打本机反应中的号码
【发布时间】:2021-03-18 13:07:36
【问题描述】:

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

【问题讨论】:

    标签: javascript react-native listener phone-call


    【解决方案1】:

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

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

    【讨论】:

    • 我试过这个我得到一个错误“null不是一个对象......评估'_reactNative.NativeModules.RNImmediatePhoneCall.immediatePhoneCall')”
    【解决方案2】:

    我已经看到了很多关于这个的东西,所以我终于得到了解决方案。所以解决方案是做一个桥 b/w 反应原生和 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" />
    

    【讨论】:

      【解决方案3】:

      你可以使用react-native-send-intent

      如果您需要直接使用电话呼叫,请在您的 AndroidManifest.xml 文件中请求权限非常重要。您可以添加一个可选的第二个参数,以修复默认手机应用程序。

      &lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt;

      如何使用

          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事件中使用上述功能

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-27
        相关资源
        最近更新 更多