5
My intention is to create a Softphone, for this I am consulting the libraries of google and doing some tests only that I have enclosed in a part.
I don’t want to do start functions, or multiple screens, or anything complicated. I just want to make a call.
I created the instances as google says and etc. Follows below my code.
Mainactivity.java
package br.com.coligarse.testevoip;
import android.net.sip.SipException;
import android.net.sip.SipManager;
import android.net.sip.SipProfile;
import android.net.sip.SipRegistrationListener;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.text.ParseException;
public class MainActivity extends AppCompatActivity {
TextView status;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SipManager mSipManager = null;
if (mSipManager == null) {
mSipManager = SipManager.newInstance(this);
}
SipProfile mSipProfile = null;
SipProfile.Builder builder = null;
try {
builder = new SipProfile.Builder("100", "voip.servidor.net.br:5082");
} catch (ParseException e) {
e.printStackTrace();
}
builder.setPassword("123456");
mSipProfile = builder.build();
try {
mSipManager.setRegistrationListener(mSipProfile.getUriString(), new SipRegistrationListener() {
public void onRegistering(String localProfileUri) {
updateStatus("Registering with SIP Server...");
}
public void onRegistrationDone(String localProfileUri, long expiryTime) {
updateStatus("Ready");
}
public void onRegistrationFailed(String localProfileUri, int errorCode,
String errorMessage) {
updateStatus("Registration failed. Please check settings.");
}
});
} catch (SipException e) {
e.printStackTrace();
}
}
public void updateStatus(String msg){
status = (TextView) findViewById(R.id.status);
status.setText(msg);
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="br.com.coligarse.testevoip">
<receiver android:name=".IncomingCallReceiver" android:label="Call Receiver"/>
...
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.INTERNET" />
...
<uses-feature android:name="android.hardware.sip.voip" android:required="true" />
<uses-feature android:name="android.hardware.wifi" android:required="true" />
<uses-feature android:name="android.hardware.microphone" android:required="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="br.com.coligarse.testevoip.MainActivity">
<TextView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
When I run this code. It opens the app blank and in the sequence it says it stopped working and closes.
Could someone tell me where I’m going wrong or give me some guidance on how to continue?
I really have doubts about how to proceed. I’ve read several documents, but I’m a beginner and I’m not finding a right Romo. My intention is to develop everything in android studio by SDK without using external plugins or NDK.
LOGCAT
--------- beginning of crash
09-12 13:06:47.543 2416-2416/br.com.coligarse.testevoip E/AndroidRuntime: FATAL EXCEPTION: main
Process: br.com.coligarse.testevoip, PID: 2416
java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.coligarse.testevoip/br.com.coligarse.testevoip.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.net.sip.SipManager.setRegistrationListener(java.lang.String, android.net.sip.SipRegistrationListener)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.net.sip.SipManager.setRegistrationListener(java.lang.String, android.net.sip.SipRegistrationListener)' on a null object reference
at br.com.coligarse.testevoip.MainActivity.onCreate(MainActivity.java:38)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Can post error log ??
– Marco Giovanni
logcat posted , a conferred by kindness
– Jasar Orion
Checks whether the
mSipProfile
or themSipManager
is not null when you callsetRegistrationListener
– Marco Giovanni