app synchronisieren

  • 3 Antworten
  • Letztes Antwortdatum
A

A.G

Neues Mitglied
0
Hallo Leute ich habe da eine frage .
Da ich schon sehr weit mit meine app bin habe ich ein Problem
Und zwar ich sende mit jeden switch einen link zur meine php datei die etwas einschaltet oder ausschaltet.
Jetzt brauche ich den Status ob der switch an oder aus ist ich speicher die werte in eine status.php
Für jeden Schalter wie bekomme ich den Wert zurück so das meine app sich alle paar Sekunden aktualisiert und die switch immer aktuell bleiben so das einer zweite Person die app anmacht und den Status der switch hat.
Ich Hofe man hat mich verstanden
Danke



Und das ist meine java classe

public class Network extends AsyncTask<String, String, String> {

@Override
protected String doInBackground(String... uri) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;

String responseString = null;
ByteArrayOutputStream out = null;
try {
response = httpclient.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
// HTTP RESPONSE CODES Server too busy/ nicht verfuegbar
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
responseString = out.toString();
} else {
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return responseString;

}


}
 
Naja so wirklich schau werde ich zumindest nicht draus was du machen möchtest.
Als Tipp: bearbeite doch deinen Beitrag nochmal und setzte den Code in einen Block -> [ CODE ] ... [ /CODE ] (ohne die Leerzeichen)
 
Also wen ich mein app starte und den ersten switch auf an setze schaltet er eine lampe an .
Aber wen ich das app schlisse und wieder starte ist der switch wieder auf aus und ich weiß nicht den Status ob er an oder aus ist
Code:
public class Network extends AsyncTask<String, String, String> {

    @Override
    protected String doInBackground(String... uri) {
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response;

        String responseString = null;
        ByteArrayOutputStream out = null;
        try {
            response = httpclient.execute(new HttpGet(uri[0]));
            StatusLine statusLine = response.getStatusLine();
            // HTTP RESPONSE CODES Server too busy/ nicht verfuegbar
            if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
                out = new ByteArrayOutputStream();
                response.getEntity().writeTo(out);
                responseString = out.toString();
            } else {
                response.getEntity().getContent().close();
                throw new IOException(statusLine.getReasonPhrase());
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return responseString;

    }


}
 
Zuletzt bearbeitet:

Ähnliche Themen

G
Antworten
0
Aufrufe
132
Gerdchen07
G
G
Antworten
1
Aufrufe
384
Gerdchen07
G
G
Antworten
13
Aufrufe
596
Gerdchen07
G
L
Antworten
2
Aufrufe
554
Lexub
L
migi01
Antworten
26
Aufrufe
1.989
migi01
migi01
Zurück
Oben Unten