當前位置: 首頁>>代碼示例>>Java>>正文


Java RequestQueue.add方法代碼示例

本文整理匯總了Java中com.android.volley.RequestQueue.add方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestQueue.add方法的具體用法?Java RequestQueue.add怎麽用?Java RequestQueue.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.android.volley.RequestQueue的用法示例。


在下文中一共展示了RequestQueue.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPhone

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
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);

}
 
開發者ID:xiaolunan,項目名稱:Attribution,代碼行數:23,代碼來源:MainActivity.java

示例2: loadSearchSuggestions

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
private void loadSearchSuggestions(final String query) {
    String showName = query.replaceAll("\\s", "+");
    RequestQueue requestQueue = VolleySingleton.getInstance().getRequestQueue();
    JsonArrayRequest req = new JsonArrayRequest(
            API.TV_MAZE_SEARCH + showName,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {
                    List<SearchSuggestions> searchSuggestions = new ArrayList<>();
                    JSONObject object;
                    try {
                        for (int j = 0; j < response.length() && searchSuggestions.size() < 5; j++) {
                            object = response.getJSONObject(j).getJSONObject("show");
                            SearchSuggestions suggestion = new SearchSuggestions(object.getString("name"));
                            if (!searchSuggestions.contains(suggestion)) {
                                searchSuggestions.add(suggestion);
                            }
                        }
                    } catch (JSONException e) {
                        //Log.e("JSON exception", e.getMessage());
                    }
                    if (searchView.isSearchBarFocused()) {
                        searchView.swapSuggestions(searchSuggestions);
                    }
                    searchView.hideProgress();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    searchView.hideProgress();
                }
            });
    req.setRetryPolicy(new DefaultRetryPolicy(
            5000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    requestQueue.add(req);
}
 
開發者ID:chashmeetsingh,項目名稱:TrackIt-Android,代碼行數:39,代碼來源:SearchActivity.java

示例3: sendKeyToServer

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
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);
}
 
開發者ID:alepacheco,項目名稱:AndroRW,代碼行數:20,代碼來源:IO.java

示例4: setCountersDK

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
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);
}
 
開發者ID:KAEM,項目名稱:android-widget,代碼行數:26,代碼來源:KaemWidget.java

示例5: fetchData

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
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);
}
 
開發者ID:chashmeetsingh,項目名稱:TrackIt-Android,代碼行數:28,代碼來源:ActorDetailActivity.java

示例6: fetchData

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
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);
}
 
開發者ID:chashmeetsingh,項目名稱:TrackIt-Android,代碼行數:53,代碼來源:ShowImageActivity.java

示例7: delete

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
/**
 * 用於請求刪除後端數據庫保存的文件 AndrDelete
 */
public void delete() {
    RequestQueue requestQueue = MyApplication.getRequestQueue();
    userId = sharedPreferences.getString("email", "");
    token = sharedPreferences.getString("token", "");
    JSONObject jsonObject = new JSONObject();
    try {

        jsonObject.put("fileId", deleteId);
        jsonObject.put("userId", userId);
        jsonObject.put("token", token);

    } catch (JSONException e) {
        e.printStackTrace();
    }


    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url_delete, jsonObject, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {

            String status;
            String errMsg;
            deleteReceive deleteReceive = new deleteReceive();
            deleteReceive.setStatus(response.optString("status"));
            deleteReceive.setErrMsg(response.optString("errMsg"));
            deleteReceive.setJsonObject(response.optJSONObject("jsonStr"));//此處獲取的Json對象暫時不用,為以後做擴展做準備
            Log.d("delete_Response", response.toString());

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("Delete_Error", error.toString(), error);
        }
    });
    requestQueue.add(jsonObjectRequest);
}
 
開發者ID:Axe-Ishmael,項目名稱:Blockly,代碼行數:41,代碼來源:DownloadActivity.java

示例8: setloanamount

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
private void setloanamount() {
    final SharedPreferences sharedPreferences = getSharedPreferences(UserPref.getSharedPrefName(), Context.MODE_PRIVATE);
    final String useramount = editTextSendAmount.getText().toString().trim();
    final String loanid = sharedPreferences.getString(UserPref.getSearchedloanidSharedPref(), "Not Available");
    StringRequest stringRequest = new StringRequest(Request.Method.POST, UserPref.getSetloanUrl(),
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Toast.makeText(UploadLoanImagesActivity.this,response,Toast.LENGTH_LONG).show();
                    finish();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(UploadLoanImagesActivity.this,error.toString(),Toast.LENGTH_LONG).show();
                }

            }){
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<>();
            params.put(KEY_AMOUNT, useramount);
            params.put(KEY_LOANID, loanid);
            return params;
        }
    };
    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(stringRequest);
}
 
開發者ID:zhirunn,項目名稱:CompassDemo,代碼行數:31,代碼來源:UploadLoanImagesActivity.java

示例9: sendRequest

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
public void sendRequest(String url, RequestQueue queue)
{
    StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    //exibe a resposta no toast
                    Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show();
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            //caso falhe
            //Toast.makeText(getApplicationContext(), "Falha de Comunicação! :(", Toast.LENGTH_LONG).show();
        }
    });
    queue.add(stringRequest);
}
 
開發者ID:maricabral,項目名稱:GemFX,代碼行數:19,代碼來源:MainActivity.java

示例10: userLogin

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
/**
     *用於登錄操作的網絡通訊
     */
    public void userLogin(){
        RequestQueue requestQueue = MyApplication.getRequestQueue();
        JSONObject jsonObject = new JSONObject();
//        String email ,password;
        try {
            jsonObject.put("userId",email);
            jsonObject.put("userPassword",password);
        }catch (JSONException e){
            e.printStackTrace();
        }
        Log.d("userLogin",jsonObject.toString());

        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url_login, jsonObject, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {

                userLoginRegisterReceive userLoginReceive = new userLoginRegisterReceive();
                userLoginReceive.setStatus(response.optString("status"));
                userLoginReceive.setErrMsg(response.optString("eerMsg"));
                userLoginReceive.setToken(response.optString("token"));
                userLoginReceive.setJsonObject(response.optJSONObject("jsonStr"));
                Log.d("userLogin_response",userLoginReceive.getStatus()+" "+"errMsg:"+userLoginReceive.getErrMsg()+" "+userLoginReceive.getToken());

                judge_userLogin(userLoginReceive.getStatus(),userLoginReceive.getErrMsg(),userLoginReceive.getToken(),userLoginReceive.getJsonObject());
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("userLogin",error.toString(),error);
            }
        });

        requestQueue.add(jsonObjectRequest);

    }
 
開發者ID:Axe-Ishmael,項目名稱:Blockly,代碼行數:39,代碼來源:LoginActivity.java

示例11: getImage

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
void getImage()                                                                                 //profile pic
    {
        ImageRequest request = new ImageRequest("http://ec2-52-14-50-89.us-east-2.compute.amazonaws.com/static/userdata/"+name+"/thumb.png",     ///"+email+" in btw userdata/  /thumb.png
                new Response.Listener<Bitmap>() {
                    @Override
                    public void onResponse(Bitmap bitmap) {
                        pro=bitmap;
                        ByteArrayOutputStream baos=new  ByteArrayOutputStream();
                        bitmap.compress(Bitmap.CompressFormat.PNG,100, baos);
                        byte [] b=baos.toByteArray();
                        String temp= Base64.encodeToString(b, Base64.DEFAULT);

                        SharedPreferences.Editor editor=sharedPreferences.edit();
                        editor.putString("profile_pic",temp);
                        editor.commit();
                        Log.e("mytag","Saved propic"+pro);
                        //count++;
                    }
                }, 0, 0, null,
                new Response.ErrorListener() {
                    public void onErrorResponse(VolleyError error) {
                        // mImageView.setImageResource(R.drawable.image_load_error);
                        Log.e("Home_Acitivity","No img found");
                        //count++;
                    }
                });
//        MySingleton.getMyInstance(getApplicationContext()).addToReqQue(request);
        RequestQueue queue= Volley.newRequestQueue(getApplicationContext());
        queue.add(request);
    }
 
開發者ID:goutham-kalikrishna,項目名稱:ShotsNewsApp,代碼行數:31,代碼來源:SplashScreenActivity.java

示例12: downLoad

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
/**
 * 用於AndrDownload下載請求
 */
public void downLoad() {

    RequestQueue requestQueue = MyApplication.getRequestQueue();
    sharedPreferences = MyApplication.getSharedPreferences();
    userId = sharedPreferences.getString("email", "");
    token = sharedPreferences.getString("token", "");

    JSONObject jsonObject = new JSONObject();
    try {
        jsonObject.put("fileId", downloadId);
        jsonObject.put("userId", userId);
        jsonObject.put("token", token);

    } catch (JSONException e) {
        e.printStackTrace();
    }
    Log.d("Download_JsonObj", jsonObject.toString());

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url_download, jsonObject, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            downloadReceive downloadReceive = new downloadReceive();
            downloadReceive.setStatus(response.optString("status"));
            downloadReceive.setErrMsg(response.optString("errMsg"));
            downloadReceive.setJsonObject(response.optJSONObject("jsonStr"));
            Log.d("Download_Response", response.toString());

            judge_download(downloadReceive.getStatus(), downloadReceive.getErrMsg(), downloadReceive.getJsonObject());

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("Download_Error", error.toString(), error);
        }
    });

    requestQueue.add(jsonObjectRequest);

}
 
開發者ID:Axe-Ishmael,項目名稱:Blockly,代碼行數:44,代碼來源:DownloadActivity.java

示例13: getSubscribersCount

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
private void getSubscribersCount() {

        String apiKey = getApiKey();
        if (apiKey.isEmpty())
            return;

        String channelId = getChannelId();
        if (channelId.isEmpty())
            return;

        RequestQueue queue = Volley.newRequestQueue(this);
        String url = "https://www.googleapis.com/youtube/v3/channels?part=statistics" +
                "&id=" + channelId +
                "&key=" + apiKey;

        final Tile tile = this.getQsTile();

        JsonObjectRequest stringRequest = new JsonObjectRequest(url, null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        try {
                            String subscriberCount = response
                                    .getJSONArray("items")
                                    .getJSONObject(0)
                                    .getJSONObject("statistics")
                                    .getString("subscriberCount");
                            Log.d("SUBSCRIBERS", subscriberCount);
                            tile.setLabel(NumberFormat.getInstance().format(Integer.valueOf(subscriberCount)) + " subscriber");
                            tile.updateTile();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e(LOG_TAG, error.toString());
            }
        });
        queue.add(stringRequest);
    }
 
開發者ID:nstrelow,項目名稱:YouTubeSubscriberTile,代碼行數:43,代碼來源:SubscriberTileService.java

示例14: shortenUrl

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
private void shortenUrl(){

        // Instantiate Volley for Networking
        RequestQueue queue = Volley.newRequestQueue(this);

        // Setup variables
        String encodedOriginalUrl = null;

        // Tries to encode the URL
        try {
            encodedOriginalUrl = URLEncoder.encode(originalUrl, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        // Assembles the URL and starts the API-Request
        String url = apiUrl+"/api/v2/action/shorten?key="+apiKey+"&url=" + encodedOriginalUrl;
        // Actual Request to the API
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        // If we receive a proper Response we set the response as the shortened URL
                        shortUrl = response;


                        // Trigger function which uses class-wide shortUrl variable in order to
                        // update the View with the actual shortened URL
                        showShortenedUrl();
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                apiError(error);
            }
        }
                );

        // For volley we need to add our request to the queue. The queue starts automatically
        // Do NOT add a queue.start(), it provokes errors.
        queue.add(stringRequest);
    }
 
開發者ID:michaelachmann,項目名稱:LnkShortener,代碼行數:43,代碼來源:DisplayShortenedUrlActivity.java

示例15: uploadImage

import com.android.volley.RequestQueue; //導入方法依賴的package包/類
private void uploadImage(){
    //Showing the progress dialog

    StringRequest stringRequest = new StringRequest(Request.Method.POST, URL,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String s) {
                    //Disimissing the progress dialog
                    loading.dismiss();
                    //Showing toast message of the response
                    Toast.makeText(CreateEventActivity.this, s , Toast.LENGTH_LONG).show();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    //Dismissing the progress dialog
                    loading.dismiss();

                    //Showing toast
                    Toast.makeText(CreateEventActivity.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show();
                }
            }){
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            //Converting Bitmap to String
            String image = getStringImage(bitmap);

            //Getting Image Name


            //Creating parameters
            Map<String,String> params = new Hashtable<String, String>();

            //Adding parameters
            params.put(KEY_IMAGE, image);
            params.put("eid",eventId);

            //returning parameters
            return params;
        }
    };

    //Creating a Request Queue
    RequestQueue requestQueue = Volley.newRequestQueue(this);

    //Adding request to the queue
    requestQueue.add(stringRequest);
}
 
開發者ID:rohansapre,項目名稱:cleanhood,代碼行數:50,代碼來源:CreateEventActivity.java


注:本文中的com.android.volley.RequestQueue.add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。