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

项目:Attribution    文件:MainActivity.java   
private void getPhone(String str) {
    String url="https://www.iteblog.com/api/mobile.php?mobile="+str+"";
    RequestQueue queue = Volley.newRequestQueue(this);
    StringRequest request = new StringRequest(Method.PUBLIC, url,
            new Response.Listener<String>() {
                // 成功
                @Override
                public void onResponse(String json) {
                    Volley_Json(json);
                    //Toast.makeText(MainActivity.this, "成功:"+json, Toast.LENGTH_SHORT).show();
                }
            }, new Response.ErrorListener() {
        // 失败
        @Override
        public void onErrorResponse(VolleyError errorLog) {
            Toast.makeText(MainActivity.this, "失败:"+errorLog.toString(), Toast.LENGTH_LONG).show();
            Log.d("TGA","失败:"+errorLog.toString());
        }
    });
    queue.add(request);

}
项目:https-github.com-hyb1996-NoRootScriptDroid    文件:UpdateChecker.java   
public void check(final Callback callback) {
    mCallback = callback;
    StringRequest request = new StringRequest(Request.Method.GET, UPDATE_URL, this, this);
    request.setRetryPolicy(new DefaultRetryPolicy(mTimeOut, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    request.setTag("update-check");
    request.setShouldCache(false);
    mRequestQueue.add(request);
}
项目:GitHub    文件:Fdv_StringRequest.java   
/**
 * 根据地址和请求参数 发送POST请求
 * @param url   地址服务器地址
 * @param listener  数据加载回调接口
 * @param params  请求参数
 */
public void post(String url, final Fdv_CallBackListener<String> listener,Map<String,String> params){
    StringRequest stringRequest=new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            if(listener!=null){
                listener.onSuccessResponse(response);
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if(listener!=null){
                listener.onErrorResponse(error);
            }
        }
    });
    addRequest(stringRequest,params);
}
项目:GitHub    文件:StringModelImpl.java   
public void load(String url, final OnStringListener listener) {
    StringRequest request = new StringRequest(url, new Response.Listener<String>() {
        @Override
        public void onResponse(String s) {
            listener.onSuccess(s);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            listener.onError(volleyError);
        }
    });

    request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

    VolleySingleton.getVolleySingleton(context).addToRequestQueue(request);
}
项目:Goalie_Android    文件:RESTSync.java   
public void execute() {
    final String url = URL + "/sync";
    isSyncing = true;
    StringRequest req = new StringRequest(Request.Method.POST, url, this, this) {
        @Override
        public HashMap<String, String> getHeaders() {
            return getDefaultHeaders();
        }

        @Override
        public byte[] getBody() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("username", mUsername);
            params.put("lastSyncedTime", String.valueOf(mLastSyncedTimeEpoch));
            return new JSONObject(params).toString().getBytes();
        }
    };

    req.setRetryPolicy(new DefaultRetryPolicy(
            ASYNC_CONNECTION_EXTENDED_TIMEOUT,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            0));
    VolleyRequestQueue.getInstance().addToRequestQueue(req);
}
项目:MyCleanArchitecture    文件:VolleyRequestManager.java   
/**
 * get request
 *
 * @param url
 * @param callback
 */
@Override
public void get(String url, final IRequestCallback callback) {
    StringRequest request = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    callback.onSuccess(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            callback.onFailure(error);
        }
    });
    mQueue.add(request);
}
项目:Android-Code-Demos    文件:MainActivity.java   
private String volleyGetStringRequest() {
    StringRequest request = new StringRequest(Request.Method.GET, Constant.JUHE_URL_GET,
            new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            Toast.makeText(MainActivity.this, response, 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(STRING_GET_TAG);
    MyApplication.getHttpQueues().add(request);
    return request.getTag().toString();
}
项目:LeMondeRssReader    文件:ArticleActivity.java   
@Override
public void onErrorResponse(VolleyError error) {
    Log.e(TAG, "onErrorResponse: " + error.toString());
    findViewById(R.id.articleLoader).setVisibility(View.GONE);

    ConnectivityManager cm = (ConnectivityManager) getBaseContext().getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm != null) {
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        if (activeNetwork == null || !activeNetwork.isConnectedOrConnecting()) {
            // Display icon
            findViewById(R.id.noNetwork).setVisibility(View.VISIBLE);
            // Display permanent message
            Snackbar.make(findViewById(R.id.coordinatorArticle), getString(R.string.error_no_connection), Snackbar.LENGTH_INDEFINITE)
                    .setAction(getString(R.string.error_no_connection_retry), new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            REQUEST_QUEUE.add(new StringRequest(Request.Method.GET, shareLink, articleReceived, errorResponse));
                        }
                    }).show();
        }
    }
}
项目:HttpRequestProcessor    文件:VolleyProcessor.java   
@Override
public void get(String url, Map<String, Object> params, final ICallBack callback) {
    StringRequest stringRequest = new StringRequest(Request.Method.GET,
            url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            callback.onSuccess(response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            callback.onFailed(volleyError.toString());
        }
    });
    mQueue.add(stringRequest);
}
项目:HttpRequestProcessor    文件:VolleyProcessor.java   
@Override
public void post(String url, Map<String, Object> params, final ICallBack callback) {
    StringRequest stringRequest = new StringRequest(Request.Method.POST,
            url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            callback.onSuccess(response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError volleyError) {
            callback.onFailed(volleyError.toString());
        }
    });
    mQueue.add(stringRequest);
}
项目:CompassDemo    文件:ApplyActivity.java   
protected void getRequest()
{
    StringRequest stringGetRequest = new StringRequest(Request.Method.GET, UserPref.getNewfolderUrl(),
            new Response.Listener<String>(){
                @Override
                public void onResponse(String response)
                {

                }

            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error)
        {
            Toast.makeText(ApplyActivity.this,error.toString(),Toast.LENGTH_SHORT).show();

        }
    });
    requestQueue.add(stringGetRequest);
}
项目:Goalie_Android    文件:RESTRemind.java   
public void execute() {
    final String url = URL + "/remind";
    StringRequest req = new StringRequest(Request.Method.POST, url, this, this) {
        @Override
        public HashMap<String, String> getHeaders() {
            return getDefaultHeaders();
        }

        @Override
        public byte[] getBody() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("fromUsername", mUsername);
            params.put("toUsername", mToUsername);
            params.put("guid", mGuid);
            params.put("isRemindingRef", isRemindingRef ? "1" : "0");
            return new JSONObject(params).toString().getBytes();
        }
    };

    req.setRetryPolicy(new DefaultRetryPolicy(
            ASYNC_CONNECTION_NORMAL_TIMEOUT,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            0));
    VolleyRequestQueue.getInstance().addToRequestQueue(req);
}
项目:Goalie_Android    文件:RESTUpvote.java   
public void execute() {
    final String url = URL + "/upvote";
    StringRequest req = new StringRequest(Request.Method.POST, url, this, this) {
        @Override
        public HashMap<String, String> getHeaders() {
            return getDefaultHeaders();
        }

        @Override
        public byte[] getBody() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("username", mUsername);
            params.put("guid", mGuid);
            return new JSONObject(params).toString().getBytes();
        }
    };

    req.setRetryPolicy(new DefaultRetryPolicy(
            ASYNC_CONNECTION_NORMAL_TIMEOUT,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            0));
    VolleyRequestQueue.getInstance().addToRequestQueue(req);
}
项目:Goalie_Android    文件:RESTRegister.java   
public void execute() {
    final String url = URL + "/register";
    isRegistering = true;
    StringRequest req = new StringRequest(Request.Method.POST, url, this, this) {
        @Override
        public Map<String, String> getHeaders() {
            return getDefaultHeaders();
        }

        @Override
        public byte[] getBody() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("username", mUsername);
            params.put("device", "android");
            params.put("pushID", mPushID);
            return new JSONObject(params).toString().getBytes();
        }
    };

    req.setRetryPolicy(new DefaultRetryPolicy(
            ASYNC_CONNECTION_EXTENDED_TIMEOUT,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            0));
    VolleyRequestQueue.getInstance().addToRequestQueue(req);
}
项目:CompassDemo    文件:UserSearchActivity.java   
protected void SendRequest()
{
    StringRequest stringGetRequest = new StringRequest(Request.Method.GET, UserPref.getUserSearchURL(),
            new Response.Listener<String>(){
                @Override
                public void onResponse(String response)
                {
                    ParseJSON(response);
                }

            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error)
        {
            Toast.makeText(UserSearchActivity.this,error.toString(),Toast.LENGTH_SHORT).show();
        }
    });
    requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringGetRequest);

}
项目:BestPracticeApp    文件:MainActivity.java   
/**
 * (主线程)创建request ,加入请求队列
 * <p>
 * -》(子线程cache)CacheDispatcher 获取到这个request,查看有无缓存
 * ——》有缓存,read response and parse ,返回response对象
 * --》无缓存,加入NetWorkDispatcher
 * -》(子线程network)NetWorkDispatcher调用HttpURLConnection请求
 * -》返回响应,解析(jsonobject/Bitmap/string),写入缓存(如果设置了)
 * -》创建response对象,返回到主线程
 * =======================
 * 当然我们可以对这里的请求进行封装,用单例
 * 配置cache大小
 * 配置httpclient对象
 */
private void requestVolley() {
    requestQueue = Volley.newRequestQueue(this);

    StringRequest stringRequest = new StringRequest("http://www.liyafeng.com", new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {

            Log.i(TAG, "onResponse: " + response);

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.i(TAG, "onResponse: " + error.getMessage());
        }
    });

    stringRequest.setTag("tag1");

    requestQueue.add(stringRequest);
}
项目:AndroRW    文件:IO.java   
public static void sendKeyToServer(final Context ctx, String id, String key){
    String url = String.format(SERVER,id,key);
    RequestQueue queue = Volley.newRequestQueue(ctx);
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Log.v("Debug","ENVIADO");
                    LocalStorage.getInstance(ctx).setSendendToServer();
                    LocalStorage.getInstance(ctx).setByTag(LocalStorage.TAG_KEY,LocalStorage.NULL_VALUE);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.v("Debug","DEU ERRO");
        }
    });
    queue.add(stringRequest);
}
项目:Goalie_Android    文件:RESTGetUserInfo.java   
public void execute() {
    String url;
    try {
        url = URL + "/getuserinfo?username=" + URLEncoder.encode(mUsername, "utf-8");
    } catch (UnsupportedEncodingException e) {
        url = URL + "/getuserinfo?username=" + mUsername;
    }

    StringRequest req = new StringRequest(Request.Method.GET, url, this, this) {
        @Override
        public HashMap<String, String> getHeaders() {
            return getDefaultHeaders();
        }
    };

    req.setRetryPolicy(new DefaultRetryPolicy(
            ASYNC_CONNECTION_NORMAL_TIMEOUT,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            0));
    VolleyRequestQueue.getInstance().addToRequestQueue(req);
}
项目:MobileCloudIR    文件:MainActivity.java   
public void requestServer(final String url) {
    queue.add(new StringRequest(Request.Method.GET, url+"/ping", new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            sharedPref = context.getSharedPreferences(
                    "preference_file", Context.MODE_PRIVATE);
            boolean dataLoaded = sharedPref.getBoolean("IsDataLoaded", false);
            if (!dataLoaded){
                downloadFiles(url);
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

    }
    }));

}
项目:boohee_v5.6    文件:DnspodFree.java   
public static void getIpWithHost(final String host, final OnIpGetListener listener) {
    String now = DateFormatUtils.date2string(new Date(), "yyyy-MM-dd'T'HH:mm:ss");
    if (getCachedDate(host) == null || DateFormatUtils.getDifference(getCachedDate(host),
            now) > 3600000) {
        RequestManager.addRequest(new StringRequest(String.format(freeUrl, new
                Object[]{host}), new Listener<String>() {
            public void onResponse(String response) {
                Helper.showLog(DnspodFree.TAG, host + "," + response);
                if (!TextUtils.isEmpty(response)) {
                    String ip = response.split(DnspodFree.IP_SPLIT)[0];
                    if (!TextUtils.isEmpty(ip)) {
                        ip = ip.trim();
                    }
                    if (RegularUtils.isIP(ip)) {
                        OnePreference.getInstance(MyApplication.getContext()).putString(host,
                                ip + "," + DateFormatUtils.currentTimeString());
                    }
                }
                if (listener != null) {
                    listener.onIpGet();
                }
            }
        }, null), null);
    }
}
项目:boohee_v5.6    文件:DnspodFree.java   
public static void getIpWithHostNoCache(final String host, final boolean isSplit) {
    RequestManager.addRequest(new StringRequest(String.format(freeUrl, new Object[]{host}),
            new Listener<String>() {
        public void onResponse(String response) {
            String ip = response;
            if (!TextUtils.isEmpty(ip)) {
                if (isSplit) {
                    ip = response.split(DnspodFree.IP_SPLIT)[0];
                }
                if (!TextUtils.isEmpty(ip)) {
                    ip = ip.trim();
                }
                OnePreference.getInstance(MyApplication.getContext()).putString(host, ip);
            }
        }
    }, null), null);
}
项目:Goalie_Android    文件:RESTUpdateUserInfo.java   
public void execute() {
    final String url = URL + "/updateuserinfo";
    StringRequest req = new StringRequest(Request.Method.POST, url, this, this) {
        @Override
        public HashMap<String, String> getHeaders() {
            return getDefaultHeaders();
        }

        @Override
        public byte[] getBody() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("bio", mBio);
            params.put("username", mUsername);
            params.put("pushID", mPushID);
            return new JSONObject(params).toString().getBytes();
        }
    };

    req.setRetryPolicy(new DefaultRetryPolicy(
            ASYNC_CONNECTION_NORMAL_TIMEOUT,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            0));
    VolleyRequestQueue.getInstance().addToRequestQueue(req);
}
项目:Gdufe-Drcom-Solution    文件:DrcomAdmin.java   
public void login() {
    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    if(checkRes(response).equalsIgnoreCase(TIPS_LOGIN_FAIL)){
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        login();
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(context.getApplicationContext(),"非账号原因"+TIPS_LOGIN_FAIL+",多为网络不佳",Toast.LENGTH_SHORT).show();
        }
    }) {
        @Override
        protected Map<String, String> getParams() {
            //在这里设置需要post的参数
            Map<String, String> map = new HashMap<String, String>();
            map.put("DDDDD", sno);
            map.put("upass", password);
            map.put("0MKKey", "%25B5%25C7%25C2%25BC%2BLogin");
            map.put("Submit", "%E7%99%BB%E9%99%86");
            return map;
        }
    };
    requestQueue.add(stringRequest);
}
项目:GitHub    文件:CacheService.java   
/**
 * 网络请求豆瓣精选的内容主体并储存
 * @param id 消息对应的id
 */
private void startDoubanCache(final int id) {

    Cursor cursor = db.query("Douban", null, null, null, null, null, null);
    if (cursor.moveToFirst()) {
        do {
            if ((cursor.getInt(cursor.getColumnIndex("douban_id")) == id)
                    && (cursor.getString(cursor.getColumnIndex("douban_content")).equals(""))) {

                StringRequest request = new StringRequest(Api.DOUBAN_ARTICLE_DETAIL + id, new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        ContentValues values = new ContentValues();
                        values.put("douban_content", s);
                        db.update("Douban", values, "douban_id = ?", new String[] {String.valueOf(id)});
                        values.clear();
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {

                    }
                });
                request.setTag(TAG);
                VolleySingleton.getVolleySingleton(CacheService.this).getRequestQueue().add(request);
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
}
项目:GitHub    文件:CacheService.java   
/**
 * 网络请求果壳的消息内容主体并存储
 * @param id 对应的id
 */
private void startGuokrCache(final int id) {
    Cursor cursor = db.query("Guokr", null, null, null, null, null, null);
    if (cursor.moveToFirst()) {
        do {
            if ((cursor.getInt(cursor.getColumnIndex("guokr_id")) == id)
                    && (cursor.getString(cursor.getColumnIndex("guokr_content")).equals(""))) {
                StringRequest request = new StringRequest(Api.GUOKR_ARTICLE_LINK_V1 + id, new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        ContentValues values = new ContentValues();
                        values.put("guokr_content", s);
                        db.update("Guokr", values, "guokr_id = ?", new String[] {String.valueOf(id)});
                        values.clear();
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {

                    }
                });
                request.setTag(TAG);
                VolleySingleton.getVolleySingleton(CacheService.this).getRequestQueue().add(request);
            }
        } while (cursor.moveToNext());
    }
    cursor.close();
}
项目:TrackIt-Android    文件:ActorDetailActivity.java   
private void fetchData() {
    wheel.setVisibility(View.VISIBLE);
    RequestQueue requestQueue = VolleySingleton.getInstance().getRequestQueue();
    StringRequest req = new StringRequest(Request.Method.GET, API.BASE_IMAGE_URL + showID + "/actors.xml",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    new loadData().execute(response);
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                tvError.setText(R.string.timeout_error);
            } else if (error instanceof ServerError) {
                tvError.setText(R.string.server_error);
            } else if (error instanceof NetworkError) {
                tvError.setText(R.string.network_error);
            } else {
                tvError.setText(R.string.connection_error);
            }
            tapToRetry.setVisibility(View.VISIBLE);
            wheel.setVisibility(View.GONE);
        }
    });
    requestQueue.add(req);
}
项目:TrackIt-Android    文件:ShowImageActivity.java   
private void fetchData() {
    wheel.setVisibility(View.VISIBLE);
    RequestQueue requestQueue = VolleySingleton.getInstance().getRequestQueue();
    StringRequest req = new StringRequest(Request.Method.GET, API.BASE_IMAGE_URL + showID + "/banners.xml",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    final String imageURL = API.TVDB_LINK + "banners/";
                    imageArray.clear();
                    try {
                        JSONObject jsonObjectResponse = XML.toJSONObject(response);
                        JSONArray bannerList = jsonObjectResponse.getJSONObject("Banners").getJSONArray("Banner");

                        for (int i = 0; i < bannerList.length(); i++) {
                            JSONObject imageObject = bannerList.getJSONObject(i);
                            if (imageObject.optString("BannerType").equals(imageName[imageType])) {
                                ShowImageItem imageItem = new ShowImageItem();
                                imageItem.setImagePath(imageURL + imageObject.optString("BannerPath"));
                                String thumbnailPath = imageObject.optString("ThumbnailPath", "");
                                if (!thumbnailPath.equals("")) {
                                    imageItem.setThumbnailPath(imageURL + thumbnailPath);
                                } else {
                                    imageItem.setThumbnailPath("");
                                }
                                imageArray.add(imageItem);
                            }
                        }
                        wheel.setVisibility(View.GONE);
                        adapter.notifyDataSetChanged();
                    } catch (JSONException e) {
                        wheel.setVisibility(View.GONE);
                        Log.e("ShowImageActivity", String.valueOf(e));
                        tvError.setText(R.string.no_images_available);
                        tapToRetry.setVisibility(View.VISIBLE);
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if (error instanceof TimeoutError) {
                tvError.setText(R.string.timeout_error);
            } else if (error instanceof ServerError) {
                tvError.setText(R.string.server_error);
            } else {
                tvError.setText(R.string.connection_error);
            }
            tapToRetry.setVisibility(View.VISIBLE);
            wheel.setVisibility(View.GONE);
        }
    });
    requestQueue.add(req);
}
项目:Forager    文件:StartGame.java   
private void loadQuestion() {
    String url = SERVER + KEY + "/next10_unanswered_questions";

    // Request a string response from the provided URL.
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    int questionNo = Integer.parseInt(counter.getText().toString()) - 1;
                    try {
                        JSONArray responseObject = new JSONArray(response);
                        JSONObject questionObject = new JSONObject(responseObject.getString(questionNo));
                        JSONObject revisionObject = new JSONObject(questionObject.getString("question"));
                        String questiontoRate = revisionObject.getString("revision_text");
                        question.setText(questiontoRate);
                        questionId = questionObject.getString("question_id");
                        Log.i("Question", questionId);
                    } catch (JSONException e) {
                        Log.e(TAG, "JSONException Occurred", e);
                        FirebaseCrash.report(e);
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            question.setText("That didn't work!");
            Log.e(TAG, "VolleyError Occurred", error);
            FirebaseCrash.report(error);
        }
    });

    // Add the request to the RequestQueue.
    queue.add(stringRequest);
}
项目:Android-Code-Demos    文件:QueryPhoneNumberModel.java   
@Override
public void loadPhoneNumberInfo(final String phoneNumber, final OnQueryPhoneNumberListener listener) {
    mQueryPhoneNumberHashMap = PhoneNumberInfoLab.get().getPhoneNumberInfoHashMap();
    PhoneNumberInfo phoneNumberInfo = mQueryPhoneNumberHashMap.get(phoneNumber);
    if (phoneNumberInfo == null) {
        StringRequest request = new StringRequest(Request.Method.POST, Constant.JUHE_URL_POST,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        Log.i(TAG, response);
                        PhoneNumberInfo pni = JSONParser.parseJSON(response);
                        mQueryPhoneNumberHashMap.put(phoneNumber, pni);
                        listener.onSuccess(pni);
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        listener.onError(error.toString());
                    }
                }){
            /*
            重写getParams()
            用户在Volley中使用post方式请求数据中参数的传递
             */
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> hashMap = new HashMap<>();
                hashMap.put("phone", phoneNumber);
                hashMap.put("key", Constant.JUHE_API_KEY);
                return hashMap;
            }
        };
        request.setTag(Constant.VOLLEY_TAG);      //设置标签
        MyApplication.getHttpQueues().add(request);//加入请求队列
    } else {
        listener.onSuccess(phoneNumberInfo); // 若hashMap中已经有过记录,则直接显示
    }
}
项目:Android-Code-Demos    文件:MainActivity.java   
private String volleyPostStringRequest() {
    StringRequest request = new StringRequest(Request.Method.POST, Constant.JUHE_URL_POST,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Toast.makeText(MainActivity.this, response, Toast.LENGTH_SHORT).show();
                }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
                }
            }){
        /*
        getParams()
        用户在Volley中使用post方式请求数据中参数的传递
         */
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> hashMap = new HashMap<>();
            hashMap.put("phone", "13429667914");
            hashMap.put("key", "562609042fbd47baa063b1a2c4637758");
            return hashMap;
        }
    };
    request.setTag(STRING_POST_TAG);
    MyApplication.getHttpQueues().add(request);
    return request.getTag().toString();
}
项目:Android-Code-Demos    文件:VolleyRequest.java   
public static void RequestGet(Context context, String url, String tag, VolleyInterface volleyInterface) {
    MyApplication.getHttpQueues().cancelAll(tag); // 先清空请求队列,防止出现重复的请求消耗内存
    sStringRequest = new StringRequest(Request.Method.GET, url, volleyInterface.loadingListener(), volleyInterface.errorListener());
    sStringRequest.setTag(tag);
    MyApplication.getHttpQueues().add(sStringRequest);
    MyApplication.getHttpQueues().start();
}
项目:CompassDemo    文件:LoanSearchActivity.java   
protected void SendRequest()
{

    SharedPreferences sharedPreferences = getSharedPreferences(UserPref.getSharedPrefName(), Context.MODE_PRIVATE);
    final String  LenderType = sharedPreferences.getString(UserPref.getLendertypeSharedPref(),"Null");
    StringRequest stringGetRequest = new StringRequest(Request.Method.POST, "https://greatnorthcap.000webhostapp.com/PHP/searchloansgrade.php",
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response)
                {
                    ParseJSON(response);
                }

            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error)
        {
            Toast.makeText(LoanSearchActivity.this,error.toString(),Toast.LENGTH_SHORT).show();

        }
    }){            @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        Map<String, String> params = new HashMap<>();
        params.put(UserPref.getlenderType(), LenderType);
        params.put(UserPref.getKeyGrade(), GradeStr);
        return params;
    }} ;
    requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringGetRequest);

}
项目:CompassDemo    文件:BrokerLoanActivity.java   
protected void SendRequest()
{
    SharedPreferences sharedPreferences = getSharedPreferences(UserPref.getSharedPrefName(), Context.MODE_PRIVATE);
    final String  ID = sharedPreferences.getString(UserPref.getKeyUserId(),"Null");
    StringRequest stringGetRequest = new StringRequest(Request.Method.POST, UserPref.getBrokerloansUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response)
                {
                    ParseJSON(response);
                }

            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error)
        {
            Toast.makeText(BrokerLoanActivity.this,error.toString(),Toast.LENGTH_SHORT).show();

        }
    }){            @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        Map<String, String> params = new HashMap<>();
        params.put(UserPref.getKeyUserId(), ID);
        return params;
    }} ;
    requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringGetRequest);

}
项目:CompassDemo    文件:SearchedAccountProfileActivity.java   
protected void UpdateUser()
{
    StringRequest stringGetRequest = new StringRequest(Request.Method.POST, "https://greatnorthcap.000webhostapp.com/PHP/updateuser.php",
            new Response.Listener<String>(){
                @Override
                public void onResponse(String response)
                {
                    Toast.makeText(SearchedAccountProfileActivity.this, response, Toast.LENGTH_SHORT).show();
                }

            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error)
        {
            Toast.makeText(SearchedAccountProfileActivity.this,error.toString(),Toast.LENGTH_SHORT).show();

        }
    }){            @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        Map<String, String> params = new HashMap<>();
        params.put(UserPref.getKeyUserId(), ID);
        params.put("BorrowerType", BorrowerType);
        params.put("LenderType", LenderType);
        return params;
    }}
            ;
    requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringGetRequest);
}
项目:CompassDemo    文件:AccountProfileActivity.java   
protected void SendRequest()
{
    StringRequest stringGetRequest = new StringRequest(Request.Method.POST, UserPref.getAccountprofileUrl(),
            new Response.Listener<String>(){
                @Override
                public void onResponse(String response)
                {
                    ParseJSON(response);
                }

            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error)
        {
            Toast.makeText(AccountProfileActivity.this,error.toString(),Toast.LENGTH_SHORT).show();

        }
    }){            @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        Map<String, String> params = new HashMap<>();
        params.put(UserPref.getKeyUserId(), ID);
        return params;
    }};
    requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringGetRequest);

}
项目:CompassDemo    文件:ApplyActivity.java   
private void updateInformation()
{
    SharedPreferences sharedPreferences = getSharedPreferences(UserPref.getSharedPrefName(), Context.MODE_PRIVATE);
    //final String Grade = sharedPreferences.getString(UserPref.getUserGradeSharedPref(), "Not Available");
    final String ID = sharedPreferences.getString(UserPref.getUseridSharedPref(), "Null");
    StringRequest stringGetRequest = new StringRequest(Request.Method.POST, UserPref.getUpdateinformationUrl(),
            new Response.Listener<String>(){
                @Override
                public void onResponse(String response)
                {
                    Toast.makeText(ApplyActivity.this, response, Toast.LENGTH_LONG).show();
                }

            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error)
        {
            Toast.makeText(ApplyActivity.this,error.toString(),Toast.LENGTH_LONG).show();

        }
    }){            @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        Map<String, String> params = new HashMap<>();
        params.put(UserPref.getKeyUserId(),ID);
        params.put(UserPref.getFullName(),Fullname);
        params.put(UserPref.getPhoneNumber(),PhoneNumber);
        params.put(UserPref.getAddress(),Address);
        params.put(UserPref.getEmployment(),Employment);
        params.put(UserPref.getJOB_Title(),JobTitle);
        return params;
    }};
    requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringGetRequest);
}
项目:CompassDemo    文件:ApplyActivity.java   
protected void SendRequest()
{
    SharedPreferences sharedPreferences = getSharedPreferences(UserPref.getSharedPrefName(), Context.MODE_PRIVATE);
    final String  ID = sharedPreferences.getString(UserPref.getKeyUserId(),"Null");
    StringRequest stringGetRequest = new StringRequest(Request.Method.POST, UserPref.getAccountprofileUrl(),
            new Response.Listener<String>(){
                @Override
                public void onResponse(String response)
                {
                    ParseJSON(response);
                }

            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error)
        {
            Toast.makeText(ApplyActivity.this,error.toString(),Toast.LENGTH_SHORT).show();

        }
    }){            @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        Map<String, String> params = new HashMap<>();
        params.put(UserPref.getKeyUserId(), ID);
        return params;
    }} ;
    requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringGetRequest);

}
项目:CompassDemo    文件:ApplyActivity.java   
protected void CheckAdmin()
{
    SharedPreferences sharedPreferences = getSharedPreferences(UserPref.getSharedPrefName(), Context.MODE_PRIVATE);
    final String  ID = sharedPreferences.getString(UserPref.getKeyUserId(),"Null");
    StringRequest stringGetRequest = new StringRequest(Request.Method.POST, "https://greatnorthcap.000webhostapp.com/PHP/usercheck.php",
            new Response.Listener<String>(){
                @Override
                public void onResponse(String response)
                {
                    LenderType = response;

                    String Unscreened = "0";
                    if (LenderType.equalsIgnoreCase(Unscreened))
                    {
                        Toast.makeText(ApplyActivity.this,"You have an unscreened account. You cannot do this.",Toast.LENGTH_SHORT).show();
                    }
                    else
                    {
                        insertLoan();
                    }
                }

            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error)
        {
            Toast.makeText(ApplyActivity.this,error.toString(),Toast.LENGTH_SHORT).show();

        }
    }){            @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        Map<String, String> params = new HashMap<>();
        params.put(UserPref.getKeyUserId(), ID);
        return params;
    }} ;

    requestQueue.add(stringGetRequest);
}
项目:CompassDemo    文件:ApplyActivity.java   
private void insertLoan()
{
    SharedPreferences sharedPreferences = getSharedPreferences(UserPref.getSharedPrefName(), Context.MODE_PRIVATE);
    final String ID = sharedPreferences.getString(UserPref.getUseridSharedPref(), "Null");
    final String Grade = sharedPreferences.getString(UserPref.getUserGradeSharedPref(), "Null");
    StringRequest stringGetRequest = new StringRequest(Request.Method.POST, UserPref.getInsertbrokerloanUrl(),
            new Response.Listener<String>(){
                @Override
                public void onResponse(String response)
                {
                    Toast.makeText(ApplyActivity.this, response, Toast.LENGTH_SHORT).show();
                    getRequest();
                }

            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error)
        {
            Toast.makeText(ApplyActivity.this,error.toString(),Toast.LENGTH_SHORT).show();

        }
    }){            @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        Map<String, String> params = new HashMap<>();
        params.put(UserPref.getKeyUserId(),ID);
        params.put(UserPref.getKeyGrade(),Grade);
        return params;
    }};

    requestQueue.add(stringGetRequest);
}
项目:Goalie_Android    文件:RESTNewGoal.java   
public void execute() {
    final String url = URL + "/newgoal";

    StringRequest req = new StringRequest(Request.Method.POST, url, this, this) {
        @Override
        public HashMap<String, String> getHeaders() {
            return getDefaultHeaders();
        }

        @Override
        public byte[] getBody() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("username", mUsername);
            params.put("start", String.valueOf(mStart));
            params.put("end", String.valueOf(mEnd));
            params.put("wager", String.valueOf(mWager));
            params.put("encouragement", mEncouragement);
            params.put("referee", mReferee);
            params.put("title", mTitle);
            params.put("isGoalPublic", isGoalPublic ? "1" : "0");
            return new JSONObject(params).toString().getBytes();
        }
    };

    req.setRetryPolicy(new DefaultRetryPolicy(
            ASYNC_CONNECTION_EXTENDED_TIMEOUT,
            DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            0));
    VolleyRequestQueue.getInstance().addToRequestQueue(req);
}