Exemplo n.º 1
0
 public void connect(KrollDict args) throws RuntimeException {
   if (device == null) {
     // this.getCapabilityToken(args.get("url").toString());
     PendingIntentProxy proxy = (PendingIntentProxy) args.get("pendingIntent");
     PendingIntent pendingIntent = proxy.getPendingIntent();
     this.getCapabilityToken(args.get("url").toString(), pendingIntent);
   }
   if (args.containsKey("params") && args.get("params") instanceof HashMap) {
     HashMap<String, String> params = (HashMap<String, String>) args.get("params");
     Map<String, String> parameters = new HashMap<String, String>();
     for (String key : params.keySet()) {
       parameters.put(key, params.get(key).toString());
     }
     connection = device.connect(parameters, null);
   } else {
     connection = device.connect(null, null);
   }
 }
  public void connect() {
    if (connection == null || connection.getState() == Connection.State.DISCONNECTED) {
      connection = device.connect(null /* parameters */, null /* ConnectionListener */);
    } else {
      // Already connected!
      Log.v(LOGTAG, "Already connected!");
    }

    if (connection == null) {
      Log.v(LOGTAG, "Failed to create new connection");
    }
  }
Exemplo n.º 3
0
 private void getCapabilityToken(String url, PendingIntent intent) {
   this.capabilityToken = null;
   this.device = null;
   try {
     this.pendingIntent = intent;
     this.capabilityToken = HttpHelper.httpGet(url);
     this.device = Twilio.createDevice(this.capabilityToken, null);
     Log.d(TAG, this.capabilityToken);
     if (this.pendingIntent != null) {
       Log.d(TAG, "setting pending intent");
       device.setIncomingIntent(pendingIntent);
     } else {
       Log.d(TAG, "incoming call unavailable");
     }
   } catch (Exception e) {
     Log.e(TAG, "Failed to obtain capability token: " + e.getLocalizedMessage());
   }
 }
Exemplo n.º 4
0
 @Override
 public void finalize() {
   if (connection != null) connection.disconnect();
   if (device != null) device.release();
 }