I am using twiloclient-android-1.1.2-3635733 in my application, the MonkeyPhone class file looks like
package com.twilio.example.hellomonkey;
import java.util.HashMap;
import java.util.Map;
import android.content.Context;
import android.util.Log;
import com.twilio.client.Connection;
import com.twilio.client.Device;
import com.twilio.client.Twilio;
import com.twilio.client.Connection.State;
public class MonkeyPhone implements Twilio.InitListener
{
private static final String TAG = "MonkeyPhone";
private Device device;
private Connection connection;
public MonkeyPhone(Context context)
{
Twilio.initialize(context, this );
}
@Override
public void onInitialized()
{
Log.d(TAG, "Twilio SDK is ready");
try {
String capabilityToken = HttpHelper.httpGet("http://www.google.com/twilio/auth.php");
device = Twilio.createDevice(capabilityToken, null );
} catch (Exception e) {
Log.e(TAG, "Failed to obtain capability token: " + e.getLocalizedMessage());
}
}
@Override
public void onError(Exception e)
{
Log.e(TAG, "Twilio SDK couldn't start: " + e.getLocalizedMessage());
}
@Override
protected void finalize()
{
if (connection != null)
connection.disconnect();
if (device != null)
device.release();
}
public void connect(String phoneNumber) {
Map<String, String> parameters = new HashMap<String, String>();
parameters.put("PhoneNumber", phoneNumber);
connection = device.connect(parameters, null );
if (connection == null)
Log.w(TAG, "Failed to create new connection");
}
public void disconnect()
{
if (connection != null) {
connection.disconnect();
connection = null;
}
Twilio.shutdown();
}
public State status()
{
connection.getState();
State statusHere = connection.getState();
return statusHere;
}
}
Hellomonkeyactivity
package com.twilio.example.hellomonkey;
import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
public class HelloMonkeyActivity extends Activity implements View.OnClickListener
{
private MonkeyPhone phone;
private EditText numberField;
@Override
public void onCreate(Bundle bundle)
{
super.onCreate(bundle);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
setContentView(R.layout.main);
phone = new MonkeyPhone(getApplicationContext());
ImageButton dialButton = (ImageButton)findViewById(R.id.dialButton);
dialButton.setOnClickListener(this);
ImageButton hangupButton = (ImageButton)findViewById(R.id.hangupButton);
hangupButton.setOnClickListener(this);
numberField = (EditText)findViewById(R.id.numberField);
}
@Override
public void onClick(View view)
{
if (view.getId() == R.id.dialButton)
phone.connect(numberField.getText().toString());
else if (view.getId() == R.id.hangupButton)
phone.disconnect();
}
}
I use this with targetSdkVersion:19
Everything works fine with the emulator that I tested on the following emulator devices - Nexus One (Android 4.4) Nexus 7 (Android 4.4) Nexus 10 (Android 4.4) and on devices with Android 4.2 and 4.3 it works fine in the emulator
It works fine with a real Xolo A600 device (Android version 4.2.2), but it is not possible to execute the following stacktree command in any higher version than in real devices, and not in the emulator. Why is that
02-19 11:58:38.492: E/AndroidRuntime(26854): FATAL EXCEPTION: Thread-18132
02-19 11:58:38.492: E/AndroidRuntime(26854): Process: com.twilio.example.hellomonkey, PID: 26854
02-19 11:58:38.492: E/AndroidRuntime(26854): java.lang.NoSuchFieldError: no type "Lcom/twilio/client/impl/useragent/config/UserAgentConfig$Callbacks;" found and so no field "callbacks" could be found in class "Lcom/twilio/client/impl/useragent/UserAgent;" or its superclasses
02-19 11:58:38.492: E/AndroidRuntime(26854): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.twilio.client.impl.useragent.config.UserAgentConfig$Callbacks" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
02-19 11:58:38.492: E/AndroidRuntime(26854): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
02-19 11:58:38.492: E/AndroidRuntime(26854): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
02-19 11:58:38.492: E/AndroidRuntime(26854): at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
02-19 11:58:38.492: E/AndroidRuntime(26854): Suppressed: java.lang.ClassNotFoundException: com.twilio.client.impl.useragent.config.UserAgentConfig$Callbacks
02-19 11:58:38.492: E/AndroidRuntime(26854): at java.lang.Class.classForName(Native Method)
02-19 11:58:38.492: E/AndroidRuntime(26854): at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
02-19 11:58:38.492: E/AndroidRuntime(26854): at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
02-19 11:58:38.492: E/AndroidRuntime(26854): at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
02-19 11:58:38.492: E/AndroidRuntime(26854): ... 1 more
02-19 11:58:38.492: E/AndroidRuntime(26854): Caused by: java.lang.NoClassDefFoundError: Class "Lcom/twilio/client/impl/useragent/config/UserAgentConfig$Callbacks;" not found
02-19 11:58:38.492: E/AndroidRuntime(26854): ... 5 more
02-19 11:58:49.404: I/Process(26854): Sending signal. PID: 26854 SIG: 9
, twilio sdk 4.2, , . ,
java.lang.NoClassDefFoundError UserAgentConfig $ Twilio
, , , , -
user3304953