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 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 GetPresenca.
public void GetPresenca(String URLGETPRESENCA) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETPRESENCA, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
presenca.setIdPresenca(response.getInt("id"));
presenca.setNome(response.getString("nome"));
presenca.setDescricao(response.getString("descricao"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Presença: 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 FastDev4Android by jiangqqlmj.
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));
}
use of com.android.volley.toolbox.JsonObjectRequest in project FastDev4Android by jiangqqlmj.
the class JsonRequestCharsetTest method specifiedCharsetJsonObject.
@Test
public void specifiedCharsetJsonObject() throws Exception {
byte[] data = jsonObjectString().getBytes(Charset.forName("ISO-8859-1"));
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=iso-8859-1");
NetworkResponse network = new NetworkResponse(data, headers);
JsonObjectRequest objectRequest = new JsonObjectRequest("", null, null, null);
Response<JSONObject> objectResponse = objectRequest.parseNetworkResponse(network);
assertNotNull(objectResponse);
assertTrue(objectResponse.isSuccess());
//don't check the text in Czech, ISO-8859-1 doesn't support some Czech characters
assertEquals(COPY_VALUE, objectResponse.result.getString(COPY_NAME));
}
Aggregations