It seems that the Android OS processes the given Strings in a different way than the Ubuntu OS. I don't know why.
After all, I fixed the problem by using MjSip instead of JAIN SIP.
Since I need RTP, SDP and some more stuff next to SIP, I decided to modify the open source Android App Sipdroid, which uses MjSip 1.6, until it fits my demands.
To do so, first get the code.
Import the project into Eclipse: File -> Import -> Existing Android Code Into Workspace.
Create a new Android project that meets your demands considering API Level and so on.
Add
<uses-permission android:name="android.permission.INTERNET" />
to the Manifest of your project.Copy all packages but the following from the Sipdroid project to your project:
- org.sipdroid.codecs and org.sipdroid.media (which I don't need yet, maybe later)
- org.sipdroid.sipua and subpackages.
Delete or comment broken references.
See the code below to send a REGISTER to a server.
Fix the Exeptions that are thrown by the Log mechanism by using
android.util.Log
instead of the given code. Finally, delete or comment the flush command that triggers a NullPointerException.
That's it.
import org.zoolu.sip.address.NameAddress;
import org.zoolu.sip.message.Message;
import org.zoolu.sip.message.MessageFactory;
import org.zoolu.sip.provider.SipProvider;
import org.zoolu.sip.provider.SipStack;
import org.zoolu.sip.transaction.TransactionClient;
import org.zoolu.sip.transaction.TransactionClientListener;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
public class MainActivity extends Activity implements TransactionClientListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread(new Runnable(){
@Override
public void run() {
try{
SipStack.init();
SipProvider sipProvider = new SipProvider(
"192.168.0.198", 5060, new String[]{"udp"}, null);
NameAddress toAddress = new NameAddress(
"sip:192.168.0.195:9876");
NameAddress fromAddress = new NameAddress(
"sip:192.168.0.198:9876");
Message message = MessageFactory.createRegisterRequest(
sipProvider,
toAddress,
fromAddress,
fromAddress,
null,
null);
TransactionClient t = new TransactionClient(
sipProvider,
message,
MainActivity.this);
t.request();
}catch(Exception e){
Log.d("MYSIP", Log.getStackTraceString(e));
}
}}).start();
}
// Interface methods
}