use of com.android.volley.toolbox.JsonObjectRequest in project yellowmessenger-sdk by yellowmessenger.
the class NotificationUtil method sendDeviceTokenToServer.
public static void sendDeviceTokenToServer(String deviceId, String username, final String authorizationToken, Context context) {
RequestQueue queue = Volley.newRequestQueue(context);
String url = "https://notifications.botplatform.io/push/registerDevice";
deviceId = FirebaseInstanceId.getInstance().getToken();
JSONObject body = new JSONObject();
try {
body.put("deviceId", deviceId);
body.put("profileId", username);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, body, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
if (response.getBoolean("success")) {
} else {
}
} catch (Exception e) {
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<>();
headers.put("bp-auth-token", authorizationToken);
return headers;
}
};
queue.add(jsonObjectRequest);
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.android.volley.toolbox.JsonObjectRequest in project IceNet by anton46.
the class NetworkManager method fromJsonObject.
private void fromJsonObject(final HashMap<String, String> headers, HashMap<String, Object> bodyRequest, String requestTag, final RequestCallback requestCallback) {
JsonObjectRequest request = new JsonObjectRequest(method, getUrlConnection(pathUrl), createBodyRequest(bodyRequest), new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject) {
Object t = new Gson().fromJson(jsonObject.toString(), classTarget.getType());
if (requestCallback != null)
requestCallback.onRequestSuccess(t);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (requestCallback != null) {
NetworkResponse response = error.networkResponse;
if (response != null)
requestCallback.onRequestError(new RequestError(response));
}
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return headers != null ? headers : super.getHeaders();
}
};
networkHelper.addToRequestQueue(request, requestTag);
}
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));
}
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 MPW by shineangelic.
the class NoobPoolInstrumentedTest method testJsonMinerRequest.
@Test
public void testJsonMinerRequest() throws Exception {
final GsonBuilder builder = new GsonBuilder();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET, Utils.getMinersStatsUrl(sharedPreferences), null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(final JSONObject response) {
Log.i(Constants.TAG, response.toString());
Gson gson = builder.create();
// Register an adapter to manage the date types as long values
MinerRoot retrieved = gson.fromJson(response.toString(), MinerRoot.class);
minerAddr = retrieved.getMiners().values().iterator().next().getAddress();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(Constants.TAG, "Error: " + error.getMessage());
}
});
// Adding request to request queue
JSONClientSingleton.getInstance(appContext).addToRequestQueue(jsonObjReq);
}
Aggregations