use of com.android.volley.VolleyError in project aplicativo by InCasa.
the class AdminActivity method getUser.
public void getUser(JSONObject json, String URLUSER) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, URLUSER, json, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
Context context = getApplicationContext();
CharSequence text = "Usuário: Sucesso !";
int duration = Toast.LENGTH_SHORT;
User user = User.getInstancia();
try {
user.setNome(response.getString("nome"));
user.setId(response.getString("id"));
} catch (JSONException e) {
e.printStackTrace();
}
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}, new Response.ErrorListener() {
// Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
Context context = getApplicationContext();
CharSequence text = "Usuário: Falha !";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.VolleyError in project aplicativo by InCasa.
the class CadastroActivity method Cadastro.
public void Cadastro(JSONObject json, String URLCADASTRO) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, URLCADASTRO, json, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Intent it = new Intent(CadastroActivity.this, LoginActivity.class);
startActivity(it);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Context context = getApplicationContext();
CharSequence text = "Erro no cadastro";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
});
// Add the request to the RequestQueue.
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.VolleyError in project aplicativo by InCasa.
the class HomeActivity method getTemperatura.
public void getTemperatura(String URLTEMPERATURA) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLTEMPERATURA, null, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
String temp = "";
try {
TextView txtTemp = (TextView) findViewById(R.id.txtTemp);
temp = response.getString("valor");
if (temp.equals("null")) {
txtTemp.setText("N/A");
} else {
temp = temp + " ºC";
txtTemp.setText(temp);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
// Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.VolleyError in project aplicativo by InCasa.
the class HomeActivity method getSensorTemperatura.
public void getSensorTemperatura(String URLGETTEMPERATURA) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETTEMPERATURA, null, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
try {
Temperatura temp = Temperatura.getInstancia();
temp.setIdTemperatura(response.getInt("id"));
temp.setNome(response.getString("nome"));
temp.setDescricao(response.getString("descricao"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
// Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.VolleyError in project aplicativo by InCasa.
the class HomeActivity method getRele4.
public void getRele4(String URLGETRELE4) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETRELE4, null, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
try {
Rele4.setIdRele(response.getInt("id"));
Rele4.setNome(response.getString("nome"));
Rele4.setDescricao(response.getString("descricao"));
Rele4.setPorta(response.getInt("porta"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
// Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
// Adiciona a requisição á fila de requisições
fila.add(req);
}
Aggregations