I want to send and receive data by Retrofit
, but only a specific data, just a letter or a number to perform an action from that ..
private void EnviarDatos(String dato) {
ConnectivityManager conectivity=(ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifi = conectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mobile = conectivity.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if(String.valueOf(wifi.getState()).equals ("CONNECTED")||(String.valueOf(mobile.getState()).equals("CONNECTED"))){
//Toast.makeText(getBaseContext(), "Si hay conexion disponible", Toast.LENGTH_SHORT).show();
if(wifi.isConnected()||(mobile.isConnected())) {
Call<Receiver> dat = SmartApiAdapter.getApiService().Receiver(1);
dat.enqueue(new Callback<Receiver>() {
@Override
public void onResponse(Call<Receiver> call, Response<Receiver> response) {
if(response.isSuccessful()) {
Receiver receiver = response.body();
String ds = receiver.getDato();
puente.obtainMessage(Integer.parseInt(ds));
Toast.makeText(getBaseContext(), "Alerta enviada, Mantenga la calma", Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Call<Receiver> call, Throwable t) {
Toast.makeText(getBaseContext(), "Mensaje no enviado", Toast.LENGTH_LONG).show();
}
});
}
}
else
Toast.makeText(getBaseContext(), "Sin conexion", Toast.LENGTH_LONG).show();
}
Here I try to receive a data of Retrofit
to then show it in my method handler()
private Handler puente = new Handler() {
@Override
public void handleMessage(Message msg) {
BT2.setText((Integer) msg.obj);
BT2.setTextColor(BT2.getContext().getResources().getColor(R.color.ROJO));
//Mostramos el mensage recibido del servidor en pantalla
//Toast.makeText(getApplicationContext(), (String) msg.obj,
//Toast.LENGTH_LONG).show();
}
};
And in the case of the shipment I do not understand the procedure to upload, for example, the letter "A" to the server.