com.android.volley.toolbox.JsonObjectRequest Java Examples
The following examples show how to use
com.android.volley.toolbox.JsonObjectRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Request.java From RestaurantApp with GNU General Public License v3.0 | 9 votes |
public void requestVolley(final VolleyCallback callback){ JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(requestMethod, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { callback.onSucces(response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { } }); requestQueue.add(jsonObjectRequest); }
Example #2
Source File: Request.java From RestaurantApp with GNU General Public License v3.0 | 6 votes |
public void requestDeleteBasket(final DeleteCallback callback, final int basketId){ JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(requestMethod, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { callback.deleteResponse(response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { } }){ @Override public byte[] getBody() { HashMap<String, String> params = new HashMap<String, String>(); params.put("basketId", String.valueOf(basketId)); return new JSONObject(params).toString().getBytes(); } }; requestQueue.add(jsonObjectRequest); }
Example #3
Source File: RegisterModelImp.java From HightCopyWX with Apache License 2.0 | 6 votes |
@Override public void sendAll(final sendAllListener listener, String userName, String number) { JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, UrlUtils.registerUrl(userName, number) , null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonObject) { listener.onSendSucceed(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { listener.onError(); } }) { @Override public Map<String, String> getHeaders() throws AuthFailureError { HashMap<String, String> header = new HashMap<>(); header.put("Authorization", "key=" + App.APP_SECRET_KEY); return header; } }; VolleyUtils.addQueue(request, "registerRequest"); }
Example #4
Source File: NetRequestUtil.java From TouchNews with Apache License 2.0 | 6 votes |
/** * get请求获取JsonObject * * @param url url * @param param param * @param listener callback */ public void getJson(String url, Map<String, String> param, final RequestListener listener) { url += prepareParam(param); JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { listener.onResponse(response); Log.i(TAG, response.toString()); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { listener.onError(error); Log.i(TAG, error.getMessage(), error); } }); mRequestQueue.add(jsonObjectRequest); }
Example #5
Source File: ChatModelImp.java From HightCopyWX with Apache License 2.0 | 6 votes |
@Override public void requestData(final requestListener listener, final String chatContent, final String number, final String regId, final ChatMessageDataHelper helper) { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, UrlUtils.chatUrl(chatContent, number, regId) , null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject jsonObject) { mChatMessageInfo = new ChatMessageInfo(chatContent, 1, CalendarUtils.getCurrentDate(), number, regId, SPUtils.getString("userPhone", "")); listener.onSucceed(mChatMessageInfo, helper); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { Log.d("TAG", volleyError.getMessage()); listener.onError(volleyError.getMessage()); } }) { @Override public Map<String, String> getHeaders() throws AuthFailureError { HashMap<String, String> header = new HashMap<>(); header.put("Authorization", "key=" + App.APP_SECRET_KEY); return header; } }; VolleyUtils.addQueue(jsonObjectRequest, "chatRequest"); }
Example #6
Source File: NetRequestUtil.java From TouchNews with Apache License 2.0 | 6 votes |
public void post(String url, final Map<String, String> param, final NetRequestUtil.RequestListener listener) { final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { listener.onResponse(response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { listener.onError(error); } }) { @Override protected Map<String, String> getParams() throws AuthFailureError { return param; } }; mRequestQueue.add(jsonObjectRequest); }
Example #7
Source File: ExchangeRateUtil.java From zap-android with MIT License | 6 votes |
public void getExchangeRates() { if (!MonetaryUtil.getInstance().getSecondCurrency().isBitcoin() || !PrefsUtil.getPrefs().contains(PrefsUtil.AVAILABLE_FIAT_CURRENCIES)) { String provider = PrefsUtil.getPrefs().getString(PrefsUtil.EXCHANGE_RATE_PROVIDER, BLOCKCHAIN_INFO); JsonObjectRequest request; switch (provider) { case BLOCKCHAIN_INFO: request = getBlockchainInfoRequest(); break; case COINBASE: request = getCoinbaseRequest(); break; default: request = getBlockchainInfoRequest(); } if (request != null) { // Adding request to request queue HttpClient.getInstance().addToRequestQueue(request, "rateRequest"); ZapLog.debug(LOG_TAG, "Exchange rate request initiated"); } } }
Example #8
Source File: StoryService.java From hex with Apache License 2.0 | 6 votes |
public Story getStory(String storyId) { String STORY_PATH = "/story"; String storyPath = mApiBaseUrl + STORY_PATH + "/" + storyId; RequestFuture<JSONObject> future = RequestFuture.newFuture(); JsonObjectRequest request = new JsonObjectRequest(storyPath, future, future); request.setRetryPolicy(RetryPolicyFactory.build()); mRequestQueue.add(request); try { JSONObject response = future.get(); return StoryMarshaller.marshall(response); } catch (Exception e) { return null; } }
Example #9
Source File: ShopFragment.java From android-kubernetes-blockchain with Apache License 2.0 | 6 votes |
public void getStateOfUser(String userId, final int failedAttempts) { try { JSONObject params = new JSONObject("{\"type\":\"query\",\"queue\":\"user_queue\",\"params\":{\"userId\":\"" + userId + "\", \"fcn\":\"getState\", \"args\":[" + userId + "]}}"); JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, BACKEND_URL + "/api/execute", params, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { InitialResultFromRabbit initialResultFromRabbit = gson.fromJson(response.toString(), InitialResultFromRabbit.class); if (initialResultFromRabbit.status.equals("success")) { getResultFromResultId("getStateOfUser",initialResultFromRabbit.resultId,0, failedAttempts); } else { Log.d(TAG, "Response is: " + response.toString()); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d(TAG, "That didn't work!"); } }); queue.add(jsonObjectRequest); } catch (JSONException e) { e.printStackTrace(); } }
Example #10
Source File: ShopFragment.java From android-kubernetes-blockchain with Apache License 2.0 | 6 votes |
public void getAllUserContracts(String userId, final int failedAttempts) { try { JSONObject params = new JSONObject("{\"type\":\"query\",\"queue\":\"user_queue\",\"params\":{\"userId\":\"" + userId + "\", \"fcn\":\"getAllUserContracts\", \"args\":[" + userId + "]}}"); JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, BACKEND_URL + "/api/execute", params, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { InitialResultFromRabbit initialResultFromRabbit = gson.fromJson(response.toString(), InitialResultFromRabbit.class); if (initialResultFromRabbit.status.equals("success")) { Log.d(TAG, "Response is: -- " + response.toString()); getResultFromResultId("getAllUserContracts",initialResultFromRabbit.resultId,0, failedAttempts); } else { Log.d(TAG, "Response is: " + response.toString()); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d(TAG, "That didn't work!"); } }); queue.add(jsonObjectRequest); } catch (JSONException e) { e.printStackTrace(); } }
Example #11
Source File: ShopFragment.java From android-kubernetes-blockchain with Apache License 2.0 | 6 votes |
public void getProductsForSale(String userId, final int failedAttempts) { try { JSONObject params = new JSONObject("{\"type\":\"query\",\"queue\":\"user_queue\",\"params\":{\"userId\":\"" + userId + "\", \"fcn\":\"getProductsForSale\", \"args\":[]}}"); JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, BACKEND_URL + "/api/execute", params, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { InitialResultFromRabbit initialResultFromRabbit = gson.fromJson(response.toString(), InitialResultFromRabbit.class); if (initialResultFromRabbit.status.equals("success")) { getResultFromResultId("getProductsForSale",initialResultFromRabbit.resultId,0, failedAttempts); } else { Log.d(TAG, "Response is: " + response.toString()); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d(TAG, "That didn't work!"); } }); queue.add(jsonObjectRequest); } catch (JSONException e) { e.printStackTrace(); } }
Example #12
Source File: LeaderboardsFragment.java From android-kubernetes-blockchain with Apache License 2.0 | 6 votes |
public void getUserFromMongo(String userId) { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, BACKEND_URL + "/registerees/info/" + userId , null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { UserInfoModel userInfoModel = gson.fromJson(response.toString(), UserInfoModel.class); userStats.setText(String.format("%s steps", String.valueOf(userInfoModel.getSteps()))); getUserPosition(String.valueOf(userInfoModel.getSteps())); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d(TAG, "That didn't work!"); } }); queue.add(jsonObjectRequest); }
Example #13
Source File: LeaderboardsFragment.java From android-kubernetes-blockchain with Apache License 2.0 | 6 votes |
public void getStatus(final int position) { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, BACKEND_URL + "/registerees/totalUsers" , null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { int totalUsers = response.getInt("count"); status.setText(String.format("You are position %d of %d", position, totalUsers)); totalNumberOfUsers = totalUsers; } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d(TAG, "That didn't work!"); } }); queue.add(jsonObjectRequest); }
Example #14
Source File: Act_NetworkListView.java From android_volley_examples with Apache License 2.0 | 6 votes |
private void loadPage() { RequestQueue queue = MyVolley.getRequestQueue(); int startIndex = 1 + mEntries.size(); JsonObjectRequest myReq = new JsonObjectRequest(Method.GET, "https://picasaweb.google.com/data/feed/api/all?q=kitten&max-results=" + RESULTS_PAGE_SIZE + "&thumbsize=160&alt=json" + "&start-index=" + startIndex, null, createMyReqSuccessListener(), createMyReqErrorListener()); queue.add(myReq); }
Example #15
Source File: UserAPIImpl.java From the-tech-frontier-app with MIT License | 6 votes |
@Override public void fetchUserInfo(String uid, String token, final DataListener<UserInfo> listener) { JsonObjectRequest request = new JsonObjectRequest(Constants.SINA_UID_TOKEN + uid + "&access_token=" + token, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { if (listener != null) { listener.onComplete(mRespHandler.parse(response)); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { VolleyLog.e("Error: ", error.getMessage()); } }); performRequest(request); }
Example #16
Source File: ApiHelper.java From android-credentials with Apache License 2.0 | 6 votes |
protected void sendRequest(String url, HashMap<String, String> params, Response.Listener success, Response.ErrorListener failure) { String secret = prefsHelper.getSecretOverride(null); if (TextUtils.isEmpty(secret)) { final int gmsVersion = getGmsVersion(getApplicationContext()); Log.d(TAG, "GMS Version: " + gmsVersion); secret = getString(R.string.server_client_secret); if (gmsVersion < VERSION_GMS_V8_MAX) { secret = getString(R.string.server_client_secret_v8); } } try { JSONObject args = new JSONObject(); args.put("client_secret", secret); for (String key: params.keySet()) { args.put(key, params.get(key)); } JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, args, success, failure); requestQueue.add(request); } catch (JSONException e) { Log.e(TAG, "Unable to make the request", e); } }
Example #17
Source File: GosScheduleSiteTool.java From Gizwits-SmartBuld_Android with MIT License | 6 votes |
private void sendDateToSite(String httpurl, JSONObject jsonObject, final OnResponListener respon) { JsonRequest<JSONObject> jsonRequest = new JsonObjectRequest(Method.POST, httpurl, jsonObject, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.i("onSite", "response -> " + response.toString()); respon.OnRespon(0, response.optString("id")); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { respon.OnRespon(1, error.toString()); error.printStackTrace(); Log.i("onSite", "sendDateToSite请求失败" + error.toString()); } }) { @Override public Map<String, String> getHeaders() { return getHeaderWithToken(); } }; mRequestQueue.add(jsonRequest); }
Example #18
Source File: UserFragment.java From android-kubernetes-blockchain with Apache License 2.0 | 6 votes |
public void getStateOfUser(String userId, final int failedAttempts) { try { JSONObject params = new JSONObject("{\"type\":\"query\",\"queue\":\"user_queue\",\"params\":{\"userId\":\"" + userId + "\", \"fcn\":\"getState\", \"args\":[" + userId + "]}}"); JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, BACKEND_URL + "/api/execute", params, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { InitialResultFromRabbit initialResultFromRabbit = gson.fromJson(response.toString(), InitialResultFromRabbit.class); if (initialResultFromRabbit.status.equals("success")) { getResultFromResultId("getStateOfUser",initialResultFromRabbit.resultId,0, failedAttempts); } else { Log.d(TAG, "Response is: " + response.toString()); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d(TAG, "That didn't work!"); } }); queue.add(jsonObjectRequest); } catch (JSONException e) { e.printStackTrace(); } }
Example #19
Source File: Request.java From RestaurantApp with GNU General Public License v3.0 | 6 votes |
public void requestVolleyTempDesk(final VolleyTemp callback, final int deskId){ final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(requestMethod, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { callback.getTempId(response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(context, String.valueOf(error), Toast.LENGTH_SHORT).show(); } }){ @Override public byte[] getBody() { HashMap<String, Integer> params = new HashMap<String, Integer>(); params.put("deskid", deskId); return new JSONObject(params).toString().getBytes(); } }; requestQueue.add(jsonObjectRequest); }
Example #20
Source File: Act_JsonRequest.java From android_volley_examples with Apache License 2.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act__json_request); mTvResult = (TextView) findViewById(R.id.tv_result); Button btnJsonRequest = (Button) findViewById(R.id.btn_json_request); btnJsonRequest.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { RequestQueue queue = MyVolley.getRequestQueue(); JsonObjectRequest myReq = new JsonObjectRequest(Method.GET, "http://echo.jsontest.com/key/value/one/two", null, createMyReqSuccessListener(), createMyReqErrorListener()); queue.add(myReq); } }); }
Example #21
Source File: Request.java From RestaurantApp with GNU General Public License v3.0 | 6 votes |
public void requestVolleyDeskList(final ChangeDeskStatus changeDeskStatus, final int orderId, final int status){ final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(requestMethod, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { changeDeskStatus.changeStatus(response); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(context, String.valueOf(error), Toast.LENGTH_SHORT).show(); } }){ @Override public byte[] getBody() { HashMap<String, Integer> params = new HashMap<String, Integer>(); params.put("orderId", orderId); params.put("status", status); return new JSONObject(params).toString().getBytes(); } }; requestQueue.add(jsonObjectRequest); }
Example #22
Source File: MainActivity.java From android-advanced-light with MIT License | 6 votes |
private void UseJsonRequest() { String requestBody = "ip=59.108.54.37"; JsonObjectRequest mJsonObjectRequest = new JsonObjectRequest(Request.Method.POST, "http://ip.taobao.com/service/getIpInfo.php?ip=59.108.54.37", new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { IpModel ipModel = new Gson().fromJson(response.toString(), IpModel.class); if (null != ipModel && null != ipModel.getData()) { String city = ipModel.getData().getCity(); Log.d(TAG, city); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e(TAG, error.getMessage(), error); } } ); mQueue.add(mJsonObjectRequest); }
Example #23
Source File: MainActivity.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
public void btnClick2(View view){ JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET , "http://www.tngou.net/api/lore/classify", null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { tv.setText(response.optString("tngou")); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { } }); queue.add(request); }
Example #24
Source File: LeaderboardsFragment.java From android-kubernetes-blockchain with Apache License 2.0 | 6 votes |
public void getUserPosition(String steps) { JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, BACKEND_URL + "/leaderboard/position/steps/" + steps , null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { userPosition.setText(String.valueOf(response.getInt("userPosition"))); getStatus(response.getInt("userPosition")); } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d(TAG, "That didn't work!"); } }); queue.add(jsonObjectRequest); }
Example #25
Source File: NetRequestUtil.java From TouchNews with Apache License 2.0 | 5 votes |
/** * get请求获取JsonObject 带Headers参数 * * @param url url * @param param param * @param listener callback */ public void getJsonWithHeaders(String url, final Map<String, String> param, final Map<String, String> headers, final RequestListener listener) { url += prepareParam(param); JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { listener.onResponse(response); // Log.i ( TAG, response.toString ( ) ); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { listener.onError(error); // Log.i ( TAG, error.getMessage ( ), error ); } }) { @Override public Map<String, String> getHeaders() throws AuthFailureError { if (headers == null) { return super.getHeaders(); } else { return headers; } } }; mRequestQueue.add(jsonObjectRequest); }
Example #26
Source File: JsonRequestCharsetTest.java From device-database with Apache License 2.0 | 5 votes |
@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)); }
Example #27
Source File: LineLoginHelper.java From custom-auth-samples with Apache License 2.0 | 5 votes |
private Task<String> getFirebaseAuthToken(Context context, final String lineAccessToken) { final TaskCompletionSource<String> source = new TaskCompletionSource<>(); // STEP 2: Exchange LINE access token for Firebase Custom Auth token HashMap<String, String> validationObject = new HashMap<>(); validationObject.put("token", lineAccessToken); // Exchange LINE Access Token for Firebase Auth Token Response.Listener<JSONObject> responseListener = new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { String firebaseToken = response.getString("firebase_token"); Log.d(TAG, "Firebase Token = " + firebaseToken); source.setResult(firebaseToken); } catch (Exception e) { source.setException(e); } } }; Response.ErrorListener errorListener = new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e(TAG, error.toString()); source.setException(error); } }; JsonObjectRequest fbTokenRequest = new JsonObjectRequest( Request.Method.POST, mLineAcessscodeVerificationEndpoint, new JSONObject(validationObject), responseListener, errorListener); NetworkSingleton.getInstance(context).addToRequestQueue(fbTokenRequest); return source.getTask(); }
Example #28
Source File: JsonRequestCharsetTest.java From device-database with Apache License 2.0 | 5 votes |
@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)); }
Example #29
Source File: MainActivity.java From custom-auth-samples with Apache License 2.0 | 5 votes |
/** * * @param kakaoAccessToken Access token retrieved after successful Kakao Login * @return Task object that will call validation server and retrieve firebase token */ private Task<String> getFirebaseJwt(final String kakaoAccessToken) { final TaskCompletionSource<String> source = new TaskCompletionSource<>(); RequestQueue queue = Volley.newRequestQueue(this); String url = getResources().getString(R.string.validation_server_domain) + "/verifyToken"; HashMap<String, String> validationObject = new HashMap<>(); validationObject.put("token", kakaoAccessToken); JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, url, new JSONObject(validationObject), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { String firebaseToken = response.getString("firebase_token"); source.setResult(firebaseToken); } catch (Exception e) { source.setException(e); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e(TAG, error.toString()); source.setException(error); } }) { @Override protected Map<String, String> getParams() { Map<String, String> params = new HashMap<>(); params.put("token", kakaoAccessToken); return params; } }; queue.add(request); return source.getTask(); }
Example #30
Source File: ProgrammaticAutocompleteToolbarActivity.java From android-places-demos with Apache License 2.0 | 5 votes |
/** * Performs a Geocoding API request and displays the result in a dialog. * * @see https://developers.google.com/maps/documentation/geocoding/intro */ private void geocodePlaceAndDisplay(AutocompletePrediction placePrediction) { // Construct the request URL final String apiKey = getString(R.string.places_api_key); final String url = "https://maps.googleapis.com/maps/api/geocode/json?place_id=%s&key=%s"; final String requestURL = String.format(url, placePrediction.getPlaceId(), apiKey); // Use the HTTP request URL for Geocoding API to get geographic coordinates for the place JsonObjectRequest request = new JsonObjectRequest(Method.GET, requestURL, null, response -> { try { // Inspect the value of "results" and make sure it's not empty JSONArray results = response.getJSONArray("results"); if (results.length() == 0) { Log.w(TAG, "No results from geocoding request."); return; } // Use Gson to convert the response JSON object to a POJO GeocodingResult result = gson.fromJson( results.getString(0), GeocodingResult.class); displayDialog(placePrediction, result); } catch (JSONException e) { e.printStackTrace(); } }, error -> Log.e(TAG, "Request failed")); // Add the request to the Request queue. queue.add(request); }