use of com.android.volley.toolbox.JsonObjectRequest in project RxJava-Android-Samples by kaushikgopal.
the class VolleyDemoFragment method getRouteData.
/**
* Converts the Asynchronous Request into a Synchronous Future that can be used to block via
* {@code Future.get()}. Observables require blocking/synchronous functions
*
* @return JSONObject
* @throws ExecutionException
* @throws InterruptedException
*/
private JSONObject getRouteData() throws ExecutionException, InterruptedException {
RequestFuture<JSONObject> future = RequestFuture.newFuture();
String url = "http://www.weather.com.cn/adat/sk/101010100.html";
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, url, future, future);
MyVolley.getRequestQueue().add(req);
return future.get();
}
use of com.android.volley.toolbox.JsonObjectRequest in project aplicativo by InCasa.
the class VozActivity method enviaComando.
public void enviaComando(JSONObject json, String URLCOMANDO) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.POST, URLCOMANDO, json, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
Context context = getApplicationContext();
CharSequence text = "Comando enviado";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
try {
String resposta = response.getString("valor");
txtSpeechOutput.setText(resposta);
txtSpeechInput.setText("");
} 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.toolbox.JsonObjectRequest in project aplicativo by InCasa.
the class FragmentRele method GetRele3.
public void GetRele3(String URLGETRELE3) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETRELE3, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
rele3.setIdRele(response.getInt("id"));
rele3.setNome(response.getString("nome"));
rele3.setDescricao(response.getString("descricao"));
rele3.setPorta(response.getInt("porta"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Relê: 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 FragmentRele method UpdateRele3.
public void UpdateRele3(JSONObject json, String URLUPDATE) {
URLUPDATE = URLUPDATE + rele3.getIdRele();
JsonObjectRequest req = new JsonObjectRequest(Request.Method.PUT, URLUPDATE, json, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Relê: 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 FragmentRele method UpdateRele1.
public void UpdateRele1(JSONObject json, String URLUPDATE) {
URLUPDATE = URLUPDATE + rele1.getIdRele();
JsonObjectRequest req = new JsonObjectRequest(Request.Method.PUT, URLUPDATE, json, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Configuração Relê: 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);
}
Aggregations