Java 类com.android.volley.toolbox.JsonObjectRequest 实例源码

项目:IelloAndroidApp    文件:HelperRete.java   
/**
 * Effettua una web request sincrona tramite Volley API, restituendo in risposta
 * l'oggetto JSON scaricato.
 */
public static JSONObject volleySyncRequest(Context c, String url) {

    // configurazione della webRequest
    RequestFuture<JSONObject> future = RequestFuture.newFuture();
    JsonObjectRequest request = new JsonObjectRequest(url, null, future, future);
    RequestQueue requestQueue = Volley.newRequestQueue(c);
    requestQueue.add(request);

    // esecuzione sincrona della webRequest
    try {
        // limita la richiesta bloccante a un massimo di 10 secondi, quindi restituisci
        // la risposta.
        return future.get(10, TimeUnit.SECONDS);

    } catch (InterruptedException | TimeoutException | ExecutionException e) {
        e.printStackTrace();
    }

    return null;
}
项目:GitHub    文件:Fdv_JsonObjectRequest.java   
/**
 * 请求返回JSONObject对象 Get请求 无参数,或者get请求的参数直接拼接在URL上面
 * @param url   请求地址
 * @param listener  数据回调接口
 */
public void get(String url, final Fdv_CallBackListener<JSONObject> listener){
    JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
                if(listener!=null){
                    listener.onSuccessResponse(response);
                }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if(listener!=null){
                listener.onErrorResponse(error);
            }
        }
    });
    addRequest(jsonObjectRequest);
}
项目:GitHub    文件:Fdv_JsonObjectRequest.java   
/**
 * 发送POST请求, 返回JSONObject对象数据
 * @param url    请求地址
 * @param listener  数据返回回调接口
 * @param params   POST请求参数
 */
public void post(String url, final Fdv_CallBackListener<JSONObject> listener,Map<String,String> params){
    JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            if(listener!=null){
                listener.onSuccessResponse(response);
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if(listener!=null){
                listener.onErrorResponse(error);
            }
        }
    });
    addRequest(jsonObjectRequest,params);
}
项目:sa-android    文件:VersionModels.java   
public static void fetchLatestVersion(final ModelListener<String> listener) {
    JsonObjectRequest r = new JsonObjectRequest(Request.Method.GET, baseURL + "/latest", null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        JSONObject result = response.getJSONObject("result");
                        String version = result.getString("android");
                        listener.onData(version, "ok");
                    } catch (Exception e) {
                        e.printStackTrace();
                        listener.onData(null, "服务器通信失败 (1)");
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
            listener.onData(null, "服务器通信失败 (1)");
        }
    });
    SAGlobal.sharedRequestQueue.add(r);
}
项目:sa-android    文件:SchoolSystemModels.java   
public static void authInit(final ModelListener<AuthInitInfo> listener) {
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, baseURL + "/auth/init", null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                JSONObject result = response.getJSONObject("result");

                AuthInitInfo authInitInfo = new AuthInitInfo();
                authInitInfo.session_id = result.getString("session_id");
                authInitInfo.captcha_enabled = result.getBoolean("captcha_enabled");

                listener.onData(authInitInfo, "ok");
            } catch (JSONException e) {
                listener.onData(null, "教务系统返回非法数据");
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onData(null, "教务系统太烂无法通信,请稍后再试");
        }
    });
    SAGlobal.sharedRequestQueue.add(req);
}
项目:sa-android    文件:AnalyticsModels.java   
public static void sendStartEvent(String installationID) {
    // Prepare parameters
    Map<String, String> map = new HashMap<>();
    map.put("installation_id", installationID);
    map.put("school", SAConfig.schoolIdentifier);
    map.put("client_version", BuildConfig.VERSION_NAME);
    map.put("device_info", SAUtils.getDeviceModel());
    JSONObject params = new JSONObject(map);

    // Make request
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, baseURL + "/start", params, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {}
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {}
    });
    SAGlobal.sharedRequestQueue.add(jsonObjectRequest);
}
项目:sa-android    文件:AnnouncementModels.java   
public static void fetchArticleBody(String articleID, final ModelListener<String> listener) {
    JsonObjectRequest r = new JsonObjectRequest(Request.Method.GET, articleURL + "?article_id=" + articleID, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        JSONObject article = response.getJSONObject("result");
                        String article_body = article.getString("article_body");
                        listener.onData(article_body, "ok");
                    } catch (JSONException e) {
                        e.printStackTrace();
                        listener.onData(null, "获取通知信息失败");
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
            listener.onData(null, "获取通知信息失败");
        }
    });
    SAGlobal.sharedRequestQueue.add(r);
}
项目:sa-android    文件:MessageBoardModels.java   
public static void submitPost(Post post, final ModelListener<Boolean> listener) {
    // Prepare parameters
    Map<String, String> map = new HashMap<>();
    map.put("installation_id", post.installation_id);
    map.put("text", post.text);
    map.put("user_name", post.user_name);
    map.put("user_contact", post.user_contact);
    JSONObject params = new JSONObject(map);

    // Make request
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, baseURL + "/posts", params, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            listener.onData(true, "发送留言成功");
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onData(false, "发送留言失败");
        }
    });
    SAGlobal.sharedRequestQueue.add(jsonObjectRequest);
}
项目:Android-Code-Demos    文件:MainActivity.java   
private String volleyPostJsonObjectRequest() {
    HashMap<String, String> hashMap = new HashMap<>();
    hashMap.put("phone", "13429667914");
    hashMap.put("key", Constant.JUHE_API_KEY);
    JSONObject object = new JSONObject(hashMap);
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, Constant.JUHE_URL_POST, object,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_SHORT).show();

                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
                }
            });
    request.setTag(JSON_OBJECT_POST_TAG);
    MyApplication.getHttpQueues().add(request);
    return request.getTag().toString();
}
项目:Android-Code-Demos    文件:MainActivity.java   
private String volleyGetJsonObjectRequest() {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, Constant.JUHE_URL_GET, null, // 用post方式时,需更改为带请求参数的Object
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_SHORT).show();
                }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
                }
        });
    request.setTag(JSON_OBJECT_GET_TAG);
    MyApplication.getHttpQueues().add(request);
    return request.getTag().toString();
}
项目:android-advanced-light    文件:MainActivity.java   
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);
}
项目:FancyTab    文件:MainActivity.java   
void getPosts() {
    String url = getArguments().getString(ARG_SECTION_URL);
    url = getString(R.string.tumblr_api_url, url);
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                JSONObject meta = response.getJSONObject("meta");
                if (meta.getInt("status") == 200) {
                    JSONArray posts = response.getJSONObject("response").getJSONArray("posts");
                    adapter.setPosts(posts);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("Activities", error.toString());
        }
    });

    VolleySingleton.getInstance(getContext()).addToRequestQueue(request);
}
项目:eBread    文件:InterfaceFATTS.java   
/**
 * Volley call for the JSON containing the voices list
 * Create the request and add it to the requestqueue, then return the result or null if there was an error
 * @param request String containing the path to the voices on the server
 */
private void voiceRequest(String request) {
    JsonObjectRequest jsonRequest = new JsonObjectRequest(this.getUrl() + request,null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    options.returnTTSOption(response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    options.returnTTSOption(null);
                }
            });
    requestQueue.addToRequestQueue(jsonRequest);


}
项目:eBread    文件:InterfaceFATTS.java   
/**
 * Volley call for the JSON containing the tokens, async method
 * Create the request and add it to the requestqueue, then return the result or null if there was an error
 * @param FATTScall HashMap containing all the data to make the HTTP request
 */
private void tokensRequest(HashMap<String, String> FATTScall) {
JsonObjectRequest jsonRequest = new JsonObjectRequest(this.getUrl()  + "/say" + "?" + InterfaceFATTS.mapToGETQuery(FATTScall),null,
    new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                prepareSyncData(response);
            }
        },
        new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                syncArray = (null);
                respondToActivity();
            }
        });
    requestQueue.addToRequestQueue(jsonRequest);


}
项目:trvlr-android    文件:ListPublicChatMembersActivity.java   
@Override
protected void onStart() {
    super.onStart();

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Traveler traveler = (Traveler) parent.getItemAtPosition(position);
            int uid1 = currentUser.getId();
            int uid2 = traveler.getId();

            AppController.getInstance().addToRequestQueue(new JsonObjectRequest(Method.GET,
                    "http://trvlr.ch:8080/api/private-chats/" + uid1 + "/" + uid2,
                    null,
                    loadPrivateChatSuccess(),
                    loadError()
            ));
        }
    });
}
项目:TheMovies    文件:PeopleTask.java   
private static void requestPersonCredits(String url, final GetMoviesCallback callback,
                                     Activity activity) {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    callback.successGetMovies(MoviesMapping.getMoviesFromCredits(response));
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    error.printStackTrace();
                    callback.errorGetMovies();
                }
            });
    VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
项目:TheMovies    文件:MoviesTask.java   
private static void requestGetTrailers(String url, final GetTrailersCallback callback,
                                         Activity activity) {

    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    callback.successGetTrailers(MoviesMapping.getTrailersFromResponse(response));
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    callback.errorGetTrailers();
                }
            });
    VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
项目:TheMovies    文件:MoviesTask.java   
private static void requestGetReviews(String url, final GetReviewsCallback callback,
                                      Activity activity) {

    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    callback.successGetReviews(MoviesMapping.getReviewsFromResponse(response));
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    callback.errorGetReviews();
                }
            });
    VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
项目:TheMovies    文件:MoviesTask.java   
private static void requestGetMovies(String url, final GetMoviesCallback callback,
                                         Activity activity) {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    callback.successGetMovies(MoviesMapping.getMoviesFromResponse(response));
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    callback.errorGetMovies();
                }
            });
    VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
项目:TheMovies    文件:MoviesTask.java   
private static void requestGetSimilarMovies(String url, final GetMoviesCallback callback,
                                         Activity activity) {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    callback.successGetSimilarMovies(MoviesMapping.getMoviesFromResponse(response));
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    callback.errorGetMovies();
                }
            });
    VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
项目:TheMovies    文件:MoviesTask.java   
private static void requestGetRecommendedMovies(String url, final GetMoviesCallback callback,
                                         Activity activity) {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    callback.successGetRecommendedMovies(MoviesMapping.getMoviesFromResponse(response));
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    callback.errorGetMovies();
                }
            });
    VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
项目:TheMovies    文件:MoviesTask.java   
private static void requestGetCredits(String url, final GetCastCallback callback,
                                         Activity activity) {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    callback.successGetCast(MoviesMapping.getCast(response));
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    callback.errorGetCast();
                }
            });
    VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
项目:TheMovies    文件:MoviesTask.java   
private static void requestGetMovie(String url, final GetMovieCallback callback,
                                         Activity activity) {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    callback.successGetMovie(MoviesMapping.getMovieFromJson(response));
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    callback.errorGetMovie();
                }
            });
    VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
项目:LD-Notify-App    文件:MainActivity.java   
private void fetchNodeNames() {
    String newNodeUrl = "https://quarkbackend.com/getfile/rishiraj22/state";
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(newNodeUrl, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            String node = "node", note = "note", vx = "vx";
            try {
                node = response.getString("node");
                note = response.getString("note");
                vx = response.getString("vx");
            } catch (JSONException e) {
                Log.e("QUARK_BACKEND", "Quark backend not working");
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("QUARK_BACKEND", "Quark backend not working");
        }
    });

}
项目:RestaurantApp    文件:Request.java   
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);

    }
项目:RestaurantApp    文件:Request.java   
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);

    }
项目:RestaurantApp    文件:Request.java   
public void requestVolleyAuth(final VolleyCallback callback, final String username, final String password){

        final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(requestMethod, url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    callback.onSuccesAuth(response);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }, 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, String> params = new HashMap<String, String>();
                params.put("username", username);
                params.put("password", password);
                return new JSONObject(params).toString().getBytes();
            }
        };

        requestQueue.add(jsonObjectRequest);

    }
项目:RestaurantApp    文件:Request.java   
public void requestVolleyDeskList(final DeskList deskList){

        final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(requestMethod, url, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                deskList.getDesk(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(context, String.valueOf(error), Toast.LENGTH_SHORT).show();
            }
        });

            requestQueue.add(jsonObjectRequest);

    }
项目:RestaurantApp    文件:Request.java   
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);

    }
项目:RestaurantApp    文件:Request.java   
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);

    }
项目:VolleySimple    文件:VolleySimple.java   
/**
 * @param apiTag         tag to uniquely distinguish Volley requests. Null is allowed
 * @param url            URL to fetch the string at
 * @param httpMethod     the request method to use (GET or POST)
 * @param params         A {@link JSONObject} to post with the request. Null is allowed and
 *                       indicates no parameters will be posted along with request.
 * @param headers        optional Http headers
 * @param serverCallback Listener to receive the String response
 */
public void placeJsonObjectRequest(@Nullable final String apiTag, String url, int httpMethod, @Nullable JSONObject params, final @Nullable HashMap<String, String> headers, final ServerCallback serverCallback) {

    Request request = new JsonObjectRequest(httpMethod, url, params, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            serverCallback.onAPIResponse(apiTag, response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            serverCallback.onErrorResponse(apiTag, error);
        }
    }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            return headers != null ? headers : super.getHeaders();
        }
    };

    request.setRetryPolicy(retryPolicy);

    addToRequestQueue(request);
}
项目:android-widget    文件:KaemWidget.java   
private static void setCountersDK(Context context) {
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, dkCountersURL, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            try {
                dkUsersCount = response.get("users").toString();
                dkProjectsCount = response.get("projects").toString();
                dkTeamsCount = response.get("teams").toString();
                dkLookupsCount = response.get("lookups").toString();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            // log error?
        }
    });

    RequestQueue requestQueue = Volley.newRequestQueue(context);
    requestQueue.add(jsonObjectRequest);
}
项目:android-widget    文件:KaemWidget.java   
private static void setCountersIO(Context context) {
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, ioCountersURL, null, new Response.Listener<JSONObject>() {

        @Override
        public void onResponse(JSONObject response) {
            try {
                ioUsersCount = response.get("users").toString();
                ioProjectsCount = response.get("projects").toString();
                ioTeamsCount = response.get("teams").toString();
                ioLookupsCount = response.get("lookups").toString();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            // log error?
        }
    });

    RequestQueue requestQueue = Volley.newRequestQueue(context);
    requestQueue.add(jsonObjectRequest);
}
项目:IelloAndroidAdminApp    文件:HelperRete.java   
/**
 * Effettua una web request sincrona tramite Volley API, restituendo in risposta
 * l'oggetto JSON scaricato.
 */
static JSONObject volleySyncRequest(Context c, String url) {

    // configurazione della webRequest
    RequestFuture<JSONObject> future = RequestFuture.newFuture();
    JsonObjectRequest request = new JsonObjectRequest(url, null, future, future);
    RequestQueue requestQueue = Volley.newRequestQueue(c);
    requestQueue.add(request);

    // esecuzione sincrona della webRequest
    try {
        // limita la richiesta bloccante a un massimo di 10 secondi, quindi restituisci
        // la risposta.
        return future.get(10, TimeUnit.SECONDS);

    } catch (InterruptedException | TimeoutException | ExecutionException e) {
        e.printStackTrace();
    }

    return null;
}
项目:pass-mobile-android    文件:SecretApi.java   
public void getSecret(String path, String username) {
    JSONObject body = getDefaultJsonBody();
    try {
        body.put(BODY_PATH, path);
        body.put(BODY_USERNAME, username);
    } catch (JSONException e) {
        e.printStackTrace();
    }

    JsonObjectRequest request = new JsonObjectRequest(
            Request.Method.POST,
            mStorageHelper.getServerAddress() + SECRET_ENDPOINT,
            body,
            this,  // Response.Listener
            this  // Response.ErrorListener
    ) {
        @Override
        public String getBodyContentType() {
            return "application/json; charset=utf-8";
        }
    };

    request.setTag(mTag);
    mRequestQueue.add(request);
}
项目:HightCopyWX    文件:ChatModelImp.java   
@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");
}
项目:Filmy    文件:UnMarkingFavorite.java   
private void getProfile(final String session_id, final String media_id) {

        String PROFILE_URI = "https://api.themoviedb.org/3/account?api_key="+api_key+"&session_id=" + session_id;

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(PROFILE_URI, null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {

                        parseOutput(response,session_id,Integer.valueOf(media_id));
                    }

                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

                Log.e("webi", "Volley Error: " + error.getCause());

            }
        });

        tmdbrequestQueue.add(jsonObjectRequest);
    }
项目:Filmy    文件:FilmySyncAdapter.java   
private void syncNowTrending() {

        final String BASE_URL = "https://api.themoviedb.org/3/movie/popular?api_key=b640f55eb6ecc47b3433cfe98d0675b1";

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(BASE_URL, null,
                new Response.Listener<JSONObject>() {
                    @Override

                    public void onResponse(JSONObject response) {
                        parseOutput(response.toString());
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

                Log.e("webi", "Volley Error: " + error.getCause());

            }
        }
        );

        tmdbrequestQueue.add(jsonObjectRequest);

    }
项目:TouchNews    文件:NetRequestUtil.java   
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 );
}
项目:minhaeiro    文件:Usuario.java   
public static void cadastrar(final Usuario usuario, final ApiListener listener) {
    JsonObjectRequest request = new JsonObjectRequest(
            Request.Method.POST,
            ApiRoutes.USUARIO.Post(),
            new JSONObject(usuario.toParams()),
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Usuario usuarioResposta = new Gson().fromJson(response.toString(), Usuario.class);
                    listener.sucesso(usuarioResposta);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.erro(error);
        }
    });
    AppController.getInstance().addToRequestQueue(request);
}