Android - Como conectar un web service a android

 
Vista:
Imágen de perfil de Ronal
Val: 6
Ha aumentado su posición en 18 puestos en Android (en relación al último mes)
Gráfica de Android

Como conectar un web service a android

Publicado por Ronal (1 intervención) el 19/05/2017 18:00:30
Hola buenos días soy nuevo en este foro y he tenido muchos problemas queriendo conectar mi web service a android.

Les explico hemos contratado un servidor en godaddy resulta que hemos subido el archivo valida.php
en la opción de :
1.archivo > administrador de archivo > Raíz de web (public_html/www) > ServiciosWeb(dentro de ServiciosWeb se encuentra el archivo valida.php).





1
Captura
2
3




213


este código es el valida.php locamente la app en android funciona perfectamente
ya la hora de querer habitarlo en linea no funciona.

que consejo me dan oh sera que la ruta esta mala
cualquier consejo nos ayudaria mucho
123123
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 40
Ha mantenido su posición en Android (en relación al último mes)
Gráfica de Android

Como conectar un web service a android

Publicado por Juan (16 intervenciones) el 23/05/2017 11:25:24
Buenas Ronal

Tu PHP devuelve algo? Según lo que planteas y el código Android (hace unos meses que no toco Android, pero bueno) que presentas, creo que te falta una cadena JSON que devuelva algo desde tu PHP.

Quizás no sea ese el error, a ver si alguien que sepa más, te dice

Un saludo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Lorena

Como conectar un web service a android

Publicado por Lorena (4 intervenciones) el 23/05/2017 18:23:11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
private class Notific extends AsyncTask<String, Void, Void> {
    VariablesGlobals global = (VariablesGlobals) getApplicationContext();
    ProgressDialog Dialog = new ProgressDialog(Notificaciones.this);
    BufferedReader reader = null;
    JSONArray resultDatos;
    JSONObject jsonResult;
    JSONObject d;
    String data = "";
    String Content;
    String result;
 
    protected void onPreExecute() {
 
        Dialog.setMessage("Cargando...");
        Dialog.setCancelable(false);
        Dialog.show();
 
    }
 
    protected Void doInBackground(String... urls) {
 
        try
        {
            String serverURL = "aqui va tu url con los parametros a enviar por get";
            URL url = new URL(serverURL);
 
            URLConnection conn = url.openConnection();
            conn.setDoOutput(true);
            OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
            wr.write(data);
            wr.flush();
 
            reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            Content = reader.readLine().toString(); // content te regresara en string lo que conteste tu ws
        }
        catch(Exception e)
        {
            Log.e("Exception", e.toString());
        }
 
        finally
        {
            try { reader.close(); }
            catch(Exception ex) {}
        }
 
        return null;
    }
 
    protected void onPostExecute(Void unused) {
 
        try {
 
            jsonResult = new JSONObject(Content); // convertir en objeto
            result = jsonResult.getString("resultado");
 
            if(result.equals("false"))
            {
                texto = new TextView(Notificaciones.this);
                texto.setText("No tienes Notificaciones pendientes");
                texto.setTextSize(12);
                texto.setGravity(1);
                texto.setTextColor(0xFFFFFFFF);
                texto.setPadding(7, 9, 7, 9);
                texto.setBackground(getResources().getDrawable(R.drawable.notificacion));
 
                layoutNotificaciones.addView(texto);
            }
            else
            {
                result = jsonResult.getString("datos");
 
                if(result.equals("false"))
                {
                    texto = new TextView(Notificaciones.this);
                    texto.setText("No tienes Notificaciones pendientes");
                    texto.setTextSize(12);
                    texto.setGravity(1);
                    texto.setTextColor(0xFFFFFFFF);
                    texto.setPadding(7, 9, 7, 9);
                    texto.setBackground(getResources().getDrawable(R.drawable.notificacion));
 
                    layoutNotificaciones.addView(texto);
                }
                else
                {
                    resultDatos = jsonResult.getJSONArray("datos");
                    for (int i = 0; i < resultDatos.length(); i++) {
                        d = resultDatos.getJSONObject(i);
 
                        titulo.add(d.getString("titulo").toString());
                        mensaje.add(d.getString("mensajecorto").toString());
                        mensajelargo.add(d.getString("mensaje").toString());
                        estatus.add(d.getString("estatus").toString());
                        rowid.add(d.getString("rowid").toString());
 
                        color = "colorSinLeer";
                        if(d.getString("estatus").equals("1"))
                            color = "colorLeido";
 
                        c.add(color);
                    }
 
                    setupList();
                }
            }
 
        } catch (JSONException e) {
            e.printStackTrace();
        }
 
        Dialog.dismiss();
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar