I am Developing an android application for making calls,using the Twilio API. I am able to make an outgoing call from the twilio android client,but I cannot receive any incoming calls. So what additional code needs to be written on the server side apart from assigning the incoming capability. I am using node js for the server.
//android code
public void onInitialized() {
new Thread(new Runnable() {
@Override
public void run() {
try {
capabilityToken = HttpHelper
.httpGet("/my server url/token");
device = Twilio.createDevice(capabilityToken,null);
/* Code to handle incoming connections */
Intent intent = new Intent(context,HelloMonkeyActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
device.setIncomingIntent(pendingIntent);
} catch (Exception e) {
Log.e(TAG,
"Failed to obtain capability token: "
+ e.getLocalizedMessage());
}
}
}).start();
}
//establish a connection
public void handleIncomingConnections(Device inDevice,
Connection inConnection) {
if (connection != null)
connection.disconnect();
connection = inConnection;
connection.accept();
}
//server code
var express=require('express');
var app=express();
var twilio=require('twilio');
var acctId='my account id';
var authToken='my token';
var applicationId='my apps id';
app.get('/token',function(req,res){
var capability=new twilio.Capability(acctId,authToken);
capability.allowClientIncoming('client');
capability.allowClientOutgoing(applicationId);
var token=capability.generate();
console.log("token:"+token);
res.send(token);
});
app.get('/call',function(req,res){
var caller_id="//Twilio number";
var twiml=new twilio.TwimlResponse();
var dialTo=req.query.DialTo;
twiml.dial(dialTo,{callerId:caller_id});
res.send(twiml.toString());
});
Try this-
device = Twilio.createDevice(capabilityToken, this);