use of com.android.volley.toolbox.JsonObjectRequest in project aplicativo by InCasa.
the class FragmentSensor method UpdatePresenca.
public void UpdatePresenca(JSONObject json, String URLUPDATE) {
URLUPDATE = URLUPDATE + presenca.getIdPresenca();
JsonObjectRequest req = new JsonObjectRequest(Request.Method.PUT, URLUPDATE, json, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(getActivity(), "Configuração Presença: Atualizado com sucesso !", Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Presença: Erro na atualização !", Toast.LENGTH_SHORT).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;
}
};
// Add the request to the RequestQueue.
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(getActivity().getApplicationContext());
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.toolbox.JsonObjectRequest in project aplicativo by InCasa.
the class FragmentSensor method GetTemperatura.
public void GetTemperatura(String URLGETTEMPERATURA) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETTEMPERATURA, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
temp.setIdTemperatura(response.getInt("id"));
temp.setNome(response.getString("nome"));
temp.setDescricao(response.getString("descricao"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Temperatura: Erro!", Toast.LENGTH_SHORT).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;
}
};
// Add the request to the RequestQueue.
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(getActivity().getApplicationContext());
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.toolbox.JsonObjectRequest in project aplicativo by InCasa.
the class FragmentSensor method GetUmidade.
public void GetUmidade(String URLGETUMIDADE) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETUMIDADE, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
umi.setIdUmidade(response.getInt("id"));
umi.setNome(response.getString("nome"));
umi.setDescricao(response.getString("descricao"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Umidade: Erro!", Toast.LENGTH_SHORT).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;
}
};
// Add the request to the RequestQueue.
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(getActivity().getApplicationContext());
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.toolbox.JsonObjectRequest in project aplicativo by InCasa.
the class FragmentSensor method UpdateUmidade.
public void UpdateUmidade(JSONObject json, String URLUPDATE) {
URLUPDATE = URLUPDATE + umi.getIdUmidade();
JsonObjectRequest req = new JsonObjectRequest(Request.Method.PUT, URLUPDATE, json, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(getActivity(), "Configuração Umidade: Atualizado com sucesso !", Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Umidade: Erro na atualização !", Toast.LENGTH_SHORT).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;
}
};
// Add the request to the RequestQueue.
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(getActivity().getApplicationContext());
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.toolbox.JsonObjectRequest in project android-volley by mcxiaoke.
the class JsonRequestCharsetTest method defaultCharsetJsonObject.
@Test
public void defaultCharsetJsonObject() throws Exception {
// UTF-8 is default charset for JSON
byte[] data = jsonObjectString().getBytes(Charset.forName("UTF-8"));
NetworkResponse network = new NetworkResponse(data);
JsonObjectRequest objectRequest = new JsonObjectRequest("", null, null, null);
Response<JSONObject> objectResponse = objectRequest.parseNetworkResponse(network);
assertNotNull(objectResponse);
assertTrue(objectResponse.isSuccess());
assertEquals(TEXT_VALUE, objectResponse.result.getString(TEXT_NAME));
assertEquals(COPY_VALUE, objectResponse.result.getString(COPY_NAME));
}
Aggregations