Como sabrán ya he terminado mi app en la plataforma de Android Studio, ahora ya como segunda fase del proyecto, es darle poco a poco mejoras, y una de ella es, el crear un menú de configuración, para ser mas exacto, que en la parte del login en la parte del action bar tenga la opción de configurar conexión, la cual sera ingresar la dirección ip del webservices a la cual se tendrá que conectar.
Así que estoy abierto a comentario y forma de realizarlo, la verdad es que no tengo idea de como implementarlo, les dejo la pantalla de activity, yo lo que tenia pensado es que al momento de seleccionar configurar conexión me abriera una pantalla o textview donde se puede ingresar la ip y se haga la conexión y el usuario pueda usar la app.
código mandar a llamar webservices y metodo
public class webService {
//Namespace of the Webservice - can be found in WSDL
private static String NAMESPACE = "http://ONControl_MobileWSCore/";
//Webservice URL - WSDL File location
private static String URL = "http://MIIP/ONControl_MobileWSCore.asmx";//Make sure you changed IP address
//SOAP Action URI again Namespace + Web method name
private static String METHOD_NAME = "Login";
//private static List arraylist;
public static String Login(String Usuario,
String Contrasena,
String Conexion)
{
String Resultado = "";
SoapObject request = new SoapObject("http://MI IP/","Login");
request.addProperty("Usuario", Usuario);
request.addProperty("Contrasena", Contrasena);
request.addProperty("Conexion", Conexion);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes=false;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,7000);
try {
androidHttpTransport.debug = true;
// Invoke web service
androidHttpTransport.call("http://MI IP/Login", envelope);
//String ss = androidHttpTransport.responseDump;
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
Resultado=response.toString();
}catch (Exception e) {
//Assign Error Status true in static variable 'errored'
//menu.errored = true;
e.printStackTrace();
}
return Resultado;
}
public static String LLenarEncabezadoCXCP(int Recurso,
String Accion,
int Id,
int Empresa,
String Folio,
Date Fecha,
int Cliente,
int Proveedor,
int Moneda,
double TipoCambio,
int BancoCuenta,
String UsuarioCaptura,
int PagoForma,
double Saldo,
double Importe,
double Financiamiento,
double Descuento,
double SubTotal,
double Retencion1,
double Retencion2,
double IEPS,
double IVA,
double ISH,
double Total,
double TotalAplicado,
String Status,
String UsuarioCancela,
double Numero1,
double Numero2,
double Numero3,
double Numero4,
double Numero5,
double Numero6,
double Numero7,
double Numero8,
double Numero9,
double Numero10,
String Texto1,
String Texto2,
String Texto3,
String Texto4,
String Texto5,
String Texto6,
String Texto7,
String Texto8,
String Texto9,
String Texto10,
Date Fecha1,
Date Fecha2,
Date Fecha3,
Date Fecha4,
Date Fecha5,
Date Fecha6,
String Observacion,
int Catalogo1,
int Catalogo2,
int Catalogo3,
int Catalogo4,
int Catalogo5,
int Catalogo6,
String OrdenCompra,
int Concepto,
String ObservacionCancelacion,
int OrigenVentaCompra,
int OrigenInventario) {
String Resultado="";
DateFormat DateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
DecimalFormat numberFormat = new DecimalFormat("0.00000");
// Create request
SoapObject request = new SoapObject("http://oncontrol.no-ip.net:9021/", "LLenarEncabezadoCXCP");
request.addProperty("Recurso", Recurso);
request.addProperty("Accion", Accion);
request.addProperty("Id", Id);
request.addProperty("Empresa", Empresa);
request.addProperty("Folio", Folio);
request.addProperty("Fecha", DateFormatter.format(Fecha));
request.addProperty("Cliente", Cliente);
request.addProperty("Proveedor", Proveedor);
request.addProperty("Moneda", Moneda);
request.addProperty("TipoCambio", numberFormat.format(TipoCambio));
request.addProperty("BancoCuenta", BancoCuenta);
request.addProperty("UsuarioCaptura", UsuarioCaptura);
request.addProperty("PagoForma", PagoForma);
request.addProperty("Saldo", numberFormat.format(Saldo));
request.addProperty("Importe", numberFormat.format(Importe));
request.addProperty("Financiamiento", numberFormat.format(Financiamiento));
request.addProperty("Descuento", numberFormat.format(Descuento));
request.addProperty("SubTotal", numberFormat.format(SubTotal));
request.addProperty("Retencion1", numberFormat.format(Retencion1));
request.addProperty("Retencion2", numberFormat.format(Retencion2));
request.addProperty("IEPS", numberFormat.format(IEPS));
request.addProperty("IVA", numberFormat.format(IVA));
request.addProperty("ISH", numberFormat.format(ISH));
request.addProperty("Total", numberFormat.format(Total));
request.addProperty("TotalAplicado", numberFormat.format(TotalAplicado));
request.addProperty("Status", Status);
request.addProperty("UsuarioCancela", UsuarioCancela);
request.addProperty("Numero1", numberFormat.format(Numero1));
request.addProperty("Numero2", numberFormat.format(Numero2));
request.addProperty("Numero3", numberFormat.format(Numero3));
request.addProperty("Numero4", numberFormat.format(Numero4));
request.addProperty("Numero5", numberFormat.format(Numero5));
request.addProperty("Numero6", numberFormat.format(Numero6));
request.addProperty("Numero7", numberFormat.format(Numero7));
request.addProperty("Numero8", numberFormat.format(Numero8));
request.addProperty("Numero9", numberFormat.format(Numero9));
request.addProperty("Numero10", numberFormat.format(Numero10));
request.addProperty("Texto1", Texto1);
request.addProperty("Texto2", Texto2);
request.addProperty("Texto3", Texto3);
request.addProperty("Texto4", Texto4);
request.addProperty("Texto5", Texto5);
request.addProperty("Texto6", Texto6);
request.addProperty("Texto7", Texto7);
request.addProperty("Texto8", Texto8);
request.addProperty("Texto9", Texto9);
request.addProperty("Texto10", Texto10);
request.addProperty("Fecha1", DateFormatter.format(Fecha1));
request.addProperty("Fecha2", DateFormatter.format(Fecha2));
request.addProperty("Fecha3", DateFormatter.format(Fecha3));
request.addProperty("Fecha4", DateFormatter.format(Fecha4));
request.addProperty("Fecha5", DateFormatter.format(Fecha5));
request.addProperty("Fecha6", DateFormatter.format(Fecha6));
request.addProperty("Observacion", Observacion);
request.addProperty("Catalogo1", Catalogo1);
request.addProperty("Catalogo2", Catalogo2);
request.addProperty("Catalogo3", Catalogo3);
request.addProperty("Catalogo4", Catalogo4);
request.addProperty("Catalogo5", Catalogo5);
request.addProperty("Catalogo6", Catalogo6);
request.addProperty("OrdenCompra", OrdenCompra);
request.addProperty("Concepto", Concepto);
request.addProperty("ObservacionCancelacion", ObservacionCancelacion);
request.addProperty("OrigenVentaCompra", OrigenVentaCompra);
request.addProperty("OrigenInventario", OrigenInventario);
// Property which holds input parameters
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = false;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 7000);
try {
androidHttpTransport.debug = true;
// Invoke web service
androidHttpTransport.call("http://oncontrol.no-ip.net:9021/LLenarEncabezadoCXCP", envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
Resultado=response.toString();
} catch (Exception e) {
//Assign Error Status true in static variable 'errored'
//menu.errored = true;
e.printStackTrace();
}
return Resultado;
}
public static String LLenarDetalleCXCP(int Recurso,
String Accion,
int Id,
int Origen,
int OrigenDocumento,
double Importe,
double Financiamiento,
double Descuento,
double SubTotal,
double Retencion1,
double Retencion2,
double IEPS,
double IVA,
double ISH,
double Total,
double Saldo,
String Referencia) {
String resultado = "";
DecimalFormat numberFormat = new DecimalFormat("0.00000");
SoapObject request = new SoapObject("http://oncontrol.no-ip.net:9021/", "LLenarDetalleCXCP");
request.addProperty("Recurso", Recurso);
request.addProperty("Accion", Accion);
request.addProperty("Id", Id);
request.addProperty("Origen", Origen);
request.addProperty("OrigenDocumento", OrigenDocumento);
request.addProperty("Importe", numberFormat.format(Importe));
request.addProperty("Financiamiento", numberFormat.format(Financiamiento));
request.addProperty("Descuento", numberFormat.format(Descuento));
request.addProperty("SubTotal", numberFormat.format(SubTotal));
request.addProperty("Retencion1", numberFormat.format(Retencion1));
request.addProperty("Retencion2", numberFormat.format(Retencion2));
request.addProperty("IEPS", numberFormat.format(IEPS));
request.addProperty("IVA", numberFormat.format(IVA));
request.addProperty("ISH", numberFormat.format(ISH));
request.addProperty("Total", numberFormat.format(Total));
request.addProperty("Saldo", numberFormat.format(Saldo));
request.addProperty("Referencia", Referencia);
// Property which holds input parameters
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = false;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 7000);
try {
androidHttpTransport.debug = true;
// Invoke web service
androidHttpTransport.call("http://oncontrol.no-ip.net:9021/LLenarDetalleCXCP", envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
resultado=response.toString();
} catch (Exception e) {
//Assign Error Status true in static variable 'errored'
//menu.errored = true;
e.printStackTrace();
}
return resultado;
}
public static String GrabarCxCP(int Recurso,
int Modulo,
int Operacion,
int Documento,
int OrigenId,
int OrigenDocumento)
{
String resultado = "";
SoapObject request = new SoapObject("http://MIIP/", "GrabarCXCP");
request.addProperty("Recurso", Recurso);
request.addProperty("Modulo", Modulo);
request.addProperty("Operacion", Operacion);
request.addProperty("Documento", Documento);
request.addProperty("OrigenId", OrigenId);
request.addProperty("OrigenDocumento", OrigenDocumento);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = false;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 7000);
try {
androidHttpTransport.debug = true;
// Invoke web service
androidHttpTransport.call("http://oncontrol.no-ip.net:9021/GrabarCXCP", envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
resultado=response.toString();
} catch (Exception e) {
//Assign Error Status true in static variable 'errored'
e.printStackTrace();
}
return resultado;
}
public static ArrayList<FormaPago> FormaPago()
{
String resultado = "";
SoapObject request = new SoapObject("http://oncontrol.no-ip.net:9021/", "CatalogoGeneral");
request.addProperty("Id", 0);
request.addProperty("Clave", "");
request.addProperty("Descripcion", "");
request.addProperty("FiltroAdicional", "");
request.addProperty("Catalogo", "sp_pagoforma");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = false;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 7000);
ArrayList<FormaPago> DetalleArray = new ArrayList<FormaPago>();
try {
androidHttpTransport.debug = true;
// Invoke web service
androidHttpTransport.call("http://oncontrol.no-ip.net:9021/CatalogoGeneral", envelope);
//String ss = androidHttpTransport.responseDump;
SoapObject SO_FormaPago = (SoapObject)((SoapObject)((SoapObject) envelope.getResponse()).getProperty(1)).getProperty(0);
for (int i = 0; i < SO_FormaPago.getPropertyCount(); i++) {
FormaPago newDetalle = new FormaPago(ONC_SYS.NullToZeroInteger(webService.WSGetPropertyNull("Id", (SoapObject) SO_FormaPago.getProperty(i))),
webService.WSGetPropertyNull("Clave", (SoapObject) SO_FormaPago.getProperty(i)),
webService.WSGetPropertyNull("Descripcion", (SoapObject) SO_FormaPago.getProperty(i)));
DetalleArray.add(newDetalle);
}
} catch (Exception e) {
//Assign Error Status true in static variable 'errored'
//menu.errored = true;
e.printStackTrace();
}
//Return booleam to calling object
//return loginStatus;
return DetalleArray;
}
private static String WSGetPropertyNull(String PropertyName, SoapObject O_SP)
{
if (O_SP.hasProperty(PropertyName)== true)
{
return O_SP.getProperty(PropertyName).toString();
}
else
{
return "";
}
}
}
Erro al guardar la ip del servidor
E/AndroidRuntime: FATAL EXCEPTION: main
Process: mx.com.oncontrol.oncontrolmovile, PID: 11120
java.lang.NullPointerException
at mx.com.oncontrol.oncontrolmovile.Login$2.onClick(Login.java:130)
at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:157)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Codigo Alertdialog
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// action with ID action_refresh was selected
case R.id.action_settings:
try {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Ingresa Dirección IP del Servidor");
//Creamos el input text y asignamos el tipo de EditText que necesitamos
final EditText input = new EditText(this);
input.setInputType(InputType.TYPE_CLASS_TEXT );
builder.setView(input); //Lo agregamos a la vista
// Agregamos los botones de Guardar/Cancelar
builder.setPositiveButton("Guardar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Almacenamos la preferencia y la dirección ip colocada
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString(" ", input.getText().toString());
editor.commit();
}
});
builder.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.show();
}catch(Exception ex){
Log.e("ERROR",ex.getMessage());
}
break;
}
return super.onOptionsItemSelected(item);
}
este es mi mtodo del del recuperado de mi preferencia y el llamdo de mi metodo
public class webService {
Context context;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String URLCONEXION = prefs.getString("ONControlWSURL","");
//Namespace of the Webservice - can be found in WSDL
//private static String NAMESPACE = "http://ONControl_MobileWSCore/";
//Webservice URL - WSDL File location
private static String URL = "http://oncontrol.no-ip.net:9021/ONControl_MobileWSCore.asmx";//Make sure you changed IP address
private String ONControlWS = URLCONEXION;//Make sure you changed IP address
//SOAP Action URI again Namespace + Web method name
//private static String METHOD_NAME = "Login";
//private static List arraylist;
public String Login(String Usuario,
String Contrasena,
String Conexion)
{
String Resultado = "";
SoapObject request = new SoapObject(ONControlWS,"Login");
request.addProperty("Usuario", Usuario);
request.addProperty("Contrasena", Contrasena);
request.addProperty("Conexion", Conexion);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes=false;
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,7000);
try {
androidHttpTransport.debug = true;
// Invoke web service
androidHttpTransport.call(ONControlWS+"/Login", envelope);
//String ss = androidHttpTransport.responseDump;
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
Resultado=response.toString();
}catch (Exception e) {
//Assign Error Status true in static variable 'errored'
//menu.errored = true;
e.printStackTrace();
}
return Resultado;
}