我正在开发一个简单的语音聊天android应用程序使用twilio。我可以打出电话,也可以使用客户姓名接听来电。这是我的twilio语音url 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文档,但没有成功。任何帮助都将不胜感激。
发布于 2016-02-23 19:48:27
你需要做的就是转到这个链接
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 .
希望这对你有用!:)
发布于 2016-10-14 20:16:53
我已经解决了这个问题,
希望能有所帮助
@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();
}
}https://stackoverflow.com/questions/20564782
复制相似问题