web services - How can I make the url configurable in the ksoap Android-studio? -
i want configurable url , , user can change running application
public string namespace ="http://tempuri.org/"; public string url; // **how can make url configurable** public int timeout = 60000; public iwsdl2codeevents eventhandler; public soapprotocolversion soapversion;
i try session variable , external file, , sqlite when trying call process , tell parameter method , give value url extracting database , application stops.
this geturl
public string geturl() { string url = null; sqlitehelper sql = new sqlitehelper(voceo.this, "servicioweb", null, 1); sqlitedatabase bd = sql.getwritabledatabase(); cursor fila = bd.rawquery(" select url direcciones idurl= 0", null); if (fila.movetofirst()) { url = fila.getstring(0); } bd.close(); return url; }
and when try call him
public vectorstring obtenerpuertas(list<headerproperty> headers){ soapserializationenvelope soapenvelope = new soapserializationenvelope(soapenvelope.ver11); soapenvelope.implicittypes = true; soapenvelope.dotnet = true; soapobject soapreq = new soapobject("http://tempuri.org/","obtenerpuertas"); soapenvelope.setoutputsoapobject(soapreq); httptransportse httptransport = new httptransportse(geturl(),timeout); // **here try** try{ if (headers!=null){ httptransport.call("http://tempuri.org/obtenerpuertas", soapenvelope,headers); }else{ httptransport.call("http://tempuri.org/obtenerpuertas", soapenvelope); } object retobj = soapenvelope.bodyin; if (retobj instanceof soapfault){ soapfault fault = (soapfault)retobj; exception ex = new exception(fault.faultstring); if (eventhandler != null) eventhandler.wsdl2codefinishedwithexception(ex); }else{ soapobject result=(soapobject)retobj; if (result.getpropertycount() > 0){ object obj = result.getproperty(0); soapobject j = (soapobject)obj; vectorstring resultvariable = new vectorstring(j); return resultvariable; } } }catch (exception e) { if (eventhandler != null) eventhandler.wsdl2codefinishedwithexception(e); e.printstacktrace(); } return null; }
what doing wrong?
you can store url in preference.
create preference screen preference.xml:
<preferencescreen xmlns:android="http://schemas.android.com/apk/res/android"> <edittextpreference android:capitalize="words" android:defaultvalue="@string/pref_ip_default_value" <------- add string in strings values (the default value ip) android:inputtype="textcapwords" android:key="@string/pref_ip_key" <------- add string in strings values (key retrieve ip) android:maxlines="1" android:selectallonfocus="true" android:singleline="true" android:title="@string/pref_title_ip" <------- add string in strings values (the label show user) /> </preferencescreen>
settingsactivity.java:
public class settingsactivity extends preferenceactivity implements preference.onpreferencechangelistener { @override public void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); addpreferencesfromresource(r.xml.pref_general); bindpreferencesummarytovalue(findpreference(getstring(r.string.pref_ip_key))); } } private void bindpreferencesummarytovalue(preference preference) { preference.setonpreferencechangelistener(this); onpreferencechange(preference, preferencemanager .getdefaultsharedpreferences(preference.getcontext()) .getstring(preference.getkey(), "")); } @override public boolean onpreferencechange(preference preference, object value) { string stringvalue = value.tostring(); preference.setsummary(stringvalue); return true; } }
and in task.java:
sharedpreferences preferences = preferencemanager.getdefaultsharedpreferences(actvitycontext); // <---- preferences manager string pref_key = actvitycontext.getstring(r.string.pref_ip_key); // <------ name of preference string pref_default = actvitycontext.getstring(r.string.pref_ip_default_value); // < ---- value variable string preferedurl = preferences.getstring(pref_key, pref_default); // <------- user defined string uri builduri = uri.parse(preferedurl).buildupon().build(); // <----- can build uri or wherever want
Comments
Post a Comment