接听来电twilio(获取拨打电话的客户的姓名)

时间:2013-12-13 10:56:10

标签: android twilio

我正在使用twilio开发一个简单的语音聊天android应用程序。我可以拨打电话,也可以使用客户端名称接听来电。这是我的twilio语音网址php脚本:

<?php
header('Content-type: text/xml');
$client= $_REQUEST["userName"];

 ?>
<Response>
    <Dial callerId="<?php echo $client ?>">
        <Client><?php echo $number;?></Client>
    </Dial>
</Response>

我需要做的是我需要向接收来电的用户显示呼叫客户端的名称,但我无法弄清楚如何获取呼叫客户端的名称。我甚至尝试过这样做,

 @Override
        public void onResume() {
            super.onResume();

            Intent intent = getIntent();
            Device device = intent.getParcelableExtra(Device.EXTRA_DEVICE);
            Connection incoming = intent
                    .getParcelableExtra(Device.EXTRA_CONNECTION);
            incoming.setConnectionListener(this);
                    String clientName =  Connection.getParameters().get(incoming.IncomingParameterFromKey);

            Log.i(TAG, "Call from : " + clientName);
        }

但我得到了以下logcat输出:

12-13 16:17:25.531: E/Voice chat sample app log(16157): Call from : 873797

我得到一个号码873797而不是客户名称。

可能有某种方法可以获取客户端的名称。我也通过twilio文档但没有成功。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

您需要做的只是转到此链接

https://www.twilio.com/user/account/phone-numbers/incoming

   1. Click on your twilio number. 
   2. Enter into the Configure Tab
  3. Go into Voice . Check the Url in Configure with:
  4. Over there you have a drop down of Caller Name Lookup that is set to disabled. Enable it .

希望这适合你! :)

答案 1 :(得分:0)

我用这个解决了这个问题,

希望有所帮助

@Override
public void onResume() {
    super.onResume();

    Intent intent = getIntent();

    if (intent != null) {
        /*
         * Determine if the receiving Intent has an extra for the incoming connection. If so,
         * remove it from the Intent to prevent handling it again next time the Activity is resumed
         */
        Device device = intent.getParcelableExtra(Device.EXTRA_DEVICE);
        Connection incomingConnection = intent.getParcelableExtra(Device.EXTRA_CONNECTION);
        if (incomingConnection == null && device == null) {
            return;
        }
        intent.removeExtra(Device.EXTRA_DEVICE);
        intent.removeExtra(Device.EXTRA_CONNECTION);

        pendingConnection = incomingConnection;
        pendingConnection.setConnectionListener(this);

        String incomingRecipientCallNumber = pendingConnection.getParameters().get(incomingConnection.IncomingParameterFromKey);

        showRecipientNumber.setText(incomingRecipientCallNumber);

        showIncomingDialog();
    }
}