android - VOIP SipDemo Registration Failed (ERROR) -
i making application has voip.
i have proven examples have been unsuccessful.
1 - try openfire
i working openfire, within configuration -> server -> telephony, have few mappings sip accounts.
2 - try 3cx (free sip server)
i have tried access android have no success:
this code (android sip demo) http://developer.android.com/guide/topics/connectivity/sip.html
user = 11 domain : 192.168.56.101 / 127.0.0.1 password = 11
always registration failed. idea ?
public class walkietalkieactivity extends activity implements view.ontouchlistener { public string sipaddress = null; public sipmanager manager = null; public sipprofile me = null; public sipaudiocall call = null; public incomingcallreceiver callreceiver; 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; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.walkietalkie); togglebutton pushtotalkbutton = (togglebutton) findviewbyid(r.id.pushtotalk); pushtotalkbutton.setontouchlistener(this); // set intent filter. used fire // incomingcallreceiver when calls sip address used // application. intentfilter filter = new intentfilter(); filter.addaction("android.sipdemo.incoming_call"); callreceiver = new incomingcallreceiver(); this.registerreceiver(callreceiver, filter); // "push talk" can serious pain when screen keeps turning off. // let's prevent that. getwindow().addflags(windowmanager.layoutparams.flag_keep_screen_on); initializemanager(); } @override public void onstart() { super.onstart(); // when preference setting activity, assume // settings have changed, , re-login new auth info. initializemanager(); } @override public void ondestroy() { super.ondestroy(); if (call != null) { call.close(); } closelocalprofile(); if (callreceiver != null) { this.unregisterreceiver(callreceiver); } } public void initializemanager() { if(manager == null) { manager = sipmanager.newinstance(this); } initializelocalprofile(); } /** * logs sip provider, registering device location * send sip calls sip address. */ public void initializelocalprofile() { if (manager == null) { return; } if (me != null) { closelocalprofile(); } sharedpreferences prefs = preferencemanager.getdefaultsharedpreferences(getbasecontext()); string username = prefs.getstring("namepref", ""); string domain = prefs.getstring("domainpref", ""); string password = prefs.getstring("passpref", ""); if (username.length() == 0 || domain.length() == 0 || password.length() == 0) { showdialog(update_settings_dialog); return; } try { sipprofile.builder builder = new sipprofile.builder(username, domain); builder.setpassword(password); me = builder.build(); intent = new intent(); i.setaction("android.sipdemo.incoming_call"); pendingintent pi = pendingintent.getbroadcast(this, 0, i, intent.fill_in_data); manager.open(me, pi, null); // listener must added after manager.open called, // otherwise methods aren't guaranteed fire. manager.setregistrationlistener(me.geturistring(), new sipregistrationlistener() { public void onregistering(string localprofileuri) { updatestatus("registering 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. "+errormessage); } }); } catch (parseexception pe) { updatestatus("connection error."); } catch (sipexception se) { updatestatus("connection error."); } } /** * closes out local profile, freeing associated objects memory * , unregistering device server. */ public void closelocalprofile() { if (manager == null) { return; } try { if (me != null) { manager.close(me.geturistring()); } } catch (exception ee) { log.d("walkietalkieactivity/ondestroy", "failed close local profile.", ee); } } /** * make outgoing call. */ public void initiatecall() { updatestatus(sipaddress); try { sipaudiocall.listener listener = new sipaudiocall.listener() { // of client's interaction sip stack // happen via listeners. making outgoing call, don't // forget set listener set things once call established. @override public void oncallestablished(sipaudiocall call) { call.startaudio(); call.setspeakermode(true); call.togglemute(); updatestatus(call); } @override public void oncallended(sipaudiocall call) { updatestatus("ready."); } }; call = manager.makeaudiocall(me.geturistring(), sipaddress, listener, 30); } catch (exception e) { log.i("walkietalkieactivity/initiatecall", "error when trying close manager.", e); if (me != null) { try { manager.close(me.geturistring()); } catch (exception ee) { log.i("walkietalkieactivity/initiatecall", "error when trying close manager.", ee); ee.printstacktrace(); } } if (call != null) { call.close(); } } } /** * updates status box @ top of ui messege of choice. * @param status string display in status box. */ public void updatestatus(final string status) { // citizen. make sure ui changes fire on ui thread. this.runonuithread(new runnable() { public void run() { textview labelview = (textview) findviewbyid(r.id.siplabel); labelview.settext(status); } }); } /** * updates status box sip address of current call. * @param call current, active call. */ public void updatestatus(sipaudiocall call) { string usename = call.getpeerprofile().getdisplayname(); if(usename == null) { usename = call.getpeerprofile().getusername(); } updatestatus(usename + "@" + call.getpeerprofile().getsipdomain()); } /** * updates whether or not user's voice muted, depending on whether button pressed. * @param v view touch event being fired. * @param event motion act on. * @return boolean returns false indicate parent view should handle touch event * would. */ public boolean ontouch(view v, motionevent event) { if (call == null) { return false; } else if (event.getaction() == motionevent.action_down && call != null && call.ismuted()) { call.togglemute(); } else if (event.getaction() == motionevent.action_up && !call.ismuted()) { call.togglemute(); } return false; } public boolean oncreateoptionsmenu(menu menu) { menu.add(0, call_address, 0, "call someone"); menu.add(0, set_auth_info, 0, "edit sip info."); menu.add(0, hang_up, 0, "end current call."); return true; } public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case call_address: showdialog(call_address); break; case set_auth_info: updatepreferences(); break; case hang_up: if(call != null) { try { call.endcall(); } catch (sipexception se) { log.d("walkietalkieactivity/onoptionsitemselected", "error ending call.", se); } call.close(); } break; } return true; } @override protected dialog oncreatedialog(int id) { switch (id) { case call_address: layoutinflater factory = layoutinflater.from(this); final view textboxview = factory.inflate(r.layout.call_address_dialog, null); return new alertdialog.builder(this) .settitle("call someone.") .setview(textboxview) .setpositivebutton( android.r.string.ok, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { edittext textfield = (edittext) (textboxview.findviewbyid(r.id.calladdress_edit)); sipaddress = textfield.gettext().tostring(); initiatecall(); } }) .setnegativebutton( android.r.string.cancel, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { // noop. } }) .create(); case update_settings_dialog: return new alertdialog.builder(this) .setmessage("please update sip account settings.") .setpositivebutton(android.r.string.ok, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { updatepreferences(); } }) .setnegativebutton( android.r.string.cancel, new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { // noop. } }) .create(); } return null; } public void updatepreferences() { intent settingsactivity = new intent(getbasecontext(), sipsettings.class); startactivity(settingsactivity); } }
what status ? launch application in debug mode , errorcode on sipregistrationlistener.
Comments
Post a Comment