我想使用我的程序(

时间:2017-03-09 23:03:32

标签: android asterisk sip voip

我目前正在开发一个用于拨打VoIP / SIP电话的应用程序 但我不知道为什么我不能注册我的RegistrationListener我不知道是什么问题 我使用星号作为sip提供者;

这是我的代码

主要活动

public class MainActivity extends AppCompatActivity {

private static final int CALL_ADDRESS = 1;
Button Connect_Button;
public SipManager manager = null;
public SipProfile MyProfile = null;
public String sipAddress = null;

public CommsController cc;

public Context ctx = this;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Connect_Button = (Button) findViewById(R.id.ConnectB);




            cc = new CommsController();
            cc.createManager(this);

            cc.createProfile("example","192.168.1.29","54321");

            cc.openProfile(ctx);

            try {
                System.out.println("+++ IS API SUPPORTED: " + cc.getManager().isApiSupported(this));
                System.out.println("+++ IS VOIP SUPORTED: " + cc.getManager().isVoipSupported(this));
                System.out.println("+++ MANAGER INSTANCE: " + cc.getManager().toString());
                boolean isOpened = cc.getManager().isOpened(cc.getMe().getUriString());
                System.out.println("+++ IS OPENED: "+isOpened);

                if(isOpened){

                    cc.createRegistrationListener();
                    cc.getManager().register(cc.getMe(), 30000, cc.getSrl());





                }

            }catch(SipException sipex){
                System.out.println(sipex.getCause()+", "+ sipex.getMessage());

            }
}



public Context getContext(){return ctx;}

public CommsController getCc() {
    return cc;
}

}

控制器

public class CommsController {

public String sipAddress = null;
public SipManager manager = null;
public SipProfile me = null;
public SipAudioCall call = null;
public Context ctx;
private PendingIntent pendingIntent;
public SipRegistrationListener srl;



private static final int CALL_ADDRESS = 1;
private static final int SET_AUTH_INFO = 2;
private static final int UPDATE_SETTINGS_DIALOG = 3;
private static final int HANG_UP = 4;

SipAudioCall.Listener listener = new SipAudioCall.Listener(){
    @Override
    public void onCallEstablished(SipAudioCall call) {
        call.startAudio();
        call.setSpeakerMode(true);
        call.toggleMute();
    }
    @Override
    public void onCallEnded(SipAudioCall call) {
        // Do something.
    }
};

public void createManager(Context context) {
    if (manager == null) {
        manager = SipManager.newInstance(context);
    }
}

public boolean createProfile(String uname, String domain, String pass){

    try {
        SipProfile.Builder builder = new SipProfile.Builder(uname, domain);
        builder.setPassword(pass);
        builder.setProtocol("TCP");
        builder.setPort(5060);
        me = builder.build();
        setMe(me);
        System.out.println("+++ User Profile = CREATED");
        return true;
    } catch (ParseException e) {
        e.printStackTrace();
        System.out.println("+++ User Profile = FAILED");

    } catch (java.text.ParseException e) {
        e.printStackTrace();
    }
    return false;
}

public void openProfile(Context context){
    try {
        System.out.println("+++ ATTEMPTING TO OPEN PROFILE: " + me.getUriString());

        Intent intent = new Intent();
        intent.setAction("android.SipDemo.INCOMING_CALL");
        pendingIntent = PendingIntent.getBroadcast(context, 0, intent, Intent.FILL_IN_DATA);
        manager.open(getMe(),pendingIntent,srl);
        System.out.println("+++ IS OPEN IN CC: " +manager.isOpened(getMe().getUriString()));

    } catch (SipException e) {
        e.printStackTrace();
        System.out.println("+++ Profile Registration = FAILED");
    }
}

public void createRegistrationListener(){
    System.out.println("+++ CREATING REG LISTENER...");

    srl = new SipRegistrationListener() {

        @Override
        public void onRegistering(String localProfileUri) {
            System.out.println("+++ REGISTERING...");
        }

        @Override
        public void onRegistrationDone(String localProfileUri, long expiryTime) {
            System.out.println("+++ READY");
        }

        @Override
        public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {
            System.out.println("+++ REGISTRATION FAILED. CHECK SETTINGS. ERROR: "+ errorCode + " MESSAGE: " +errorMessage);
        }
    };

}
public SipRegistrationListener getSrl(){
    return srl;
}

public void closeProfile(SipProfile toClose){
    if(manager==null){
        return;
    }
    try {
        if (manager != null) {
            manager.close(toClose.getUriString());
            System.out.println("PROFILE CLOSED: " +toClose.getUriString());
        }
    } catch (Exception ee) {
        ee.printStackTrace();
        System.out.println("FAILED TO CLOSE LOCAL PROFILE: "+ toClose.toString());
    }

}

public void logOut(){
    try {
        System.out.println("+++ DEREGISTERING...");
        manager.close(me.getUriString());
    }catch(SipException se){
        System.out.println("+++ DEREGISTRATION FAILED");
        se.printStackTrace();
    }
}

public void makeCall(String toCall){
    try {
        call = manager.makeAudioCall(me.getUriString(), toCall, listener, 30);
    } catch (SipException e) {
        e.printStackTrace();
    }
}

public void setMe(SipProfile me) {
    this.me = me;
}

public SipProfile getMe() {
    return me;
}

public SipManager getManager() {
    return manager;
}

public void setManager(SipManager manager) {
    this.manager = manager;
}

}

输出

I/System.out: +++ User Profile = CREATED
I/System.out: +++ ATTEMPTING TO OPEN PROFILE:  sip:example@192.168.1.29;transport=tcp
I/System.out: +++ IS OPEN IN CC: true
I/System.out: +++ IS API SUPPORTED: true
I/System.out: +++ IS VOIP SUPORTED: true
I/System.out: +++ MANAGER INSTANCE: android.net.sip.SipManager@41bccd58
I/System.out: +++ IS OPENED: true
I/System.out: +++ CREATING REG LISTENER...
D/OpenGLRenderer: Enabling debug mode 0
I/System.out: +++ REGISTRATION FAILED. CHECK SETTINGS. ERROR: -4 MESSAGE:   libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)

请帮助我......

1 个答案:

答案 0 :(得分:1)

没有办法回答这个问题,因为这是调试问题,不是问题。

建议的调试方式如下:

  1. 获得100%正常工作的软电话,例如zoiper或xlite
  2. 将其连接到星号。
  3. 获取wireshark或tcpdump并获取sip数据包转储
  4. 获取项目转储
  5. 进行比较。