Last active
November 9, 2016 22:12
-
-
Save tatai/99821db2014448c2263dbc7b17857c0b to your computer and use it in GitHub Desktop.
Peticiones HTTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WelcomeMessage { | |
private String message = null; | |
public WelcomeMessage(String message) { | |
this.message = message; | |
} | |
public String getMessage() { | |
return this.message; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.util.Log; | |
import android.widget.Toast; | |
import com.loopj.android.http.AsyncHttpResponseHandler; | |
import org.apache.http.Header; | |
import java.io.IOException; | |
public class WelcomeResponseHandler extends AsyncHttpResponseHandler { | |
private Context context = null; | |
public WelcomeResponseHandler(Context context) { | |
this.context = context; | |
} | |
@Override | |
public void onSuccess(int i, Header[] headers, byte[] bytes) { | |
// En bytes está el contenido de la respuesta | |
// Aquí debes incluir el código que permite convertir la respuesta (que es un JSON) en un objeto Java | |
WelcomeMessage message = ... | |
Toast.makeText(this.context, message.getMessage(), Toast.LENGTH_LONG).show(); | |
} | |
@Override | |
public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) { | |
Log.d("WelcomeResponseHandler", "Request returned error " + i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment