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

项目: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);

}
项目: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;
}
项目:LaravelNewsApp    文件:rssRequest.java   
public static void requestPosts(final onGetPosts callback){
    RequestQueue queue = Volley.newRequestQueue(App.getAppContext());
    StringRequest stringRequest = new StringRequest(
            Request.Method.GET,
            request.URL.LARAVEL_FEED_URL_LIVE,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    //finally return the posts list
                    VolleyResponseHelper responseHelper = new VolleyResponseHelper(response);
                    callback.onSuccess(responseHelper.getPosts());
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d(App.Tag,"error : "+VolleyErrorHelper.getMessage(error));
                    callback.onFailure(error);
                }
            }
    );

    queue.add(stringRequest);
}
项目: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;
}
项目: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);
}
项目:android-advanced-light    文件:MainActivity.java   
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv_image = (ImageView) this.findViewById(R.id.iv_image);
        bt_send = (Button) this.findViewById(R.id.bt_send);
        nv_image = (NetworkImageView) this.findViewById(R.id.nv_image);
        mQueue = Volley.newRequestQueue(getApplicationContext());
        bt_send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                UseStringRequest();
                  UseJsonRequest();
//                UseImageRequest();
//                UseImageLoader();
//                UseNetworkImageView();
            }
        });
    }
项目: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);

}
项目:android-volley-file-upload    文件:MyApplication.java   
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    }

    return mRequestQueue;
}
项目:Nearby    文件:CustomApplication.java   
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    }

    return mRequestQueue;
}
项目:GitHub    文件:VolleyUrlLoader.java   
private static RequestQueue getInternalQueue(Context context) {
  if (internalQueue == null) {
    synchronized (Factory.class) {
      if (internalQueue == null) {
        internalQueue = Volley.newRequestQueue(context);
      }
    }
  }
  return internalQueue;
}
项目:GitHub    文件:VolleyStreamFetcherServerTest.java   
@Before
public void setUp() throws IOException {
  MockitoAnnotations.initMocks(this);

  waitForResponseLatch = new CountDownLatch(1);
  doAnswer(new CountDown()).when(callback).onDataReady(any(InputStream.class));
  doAnswer(new CountDown()).when(callback).onLoadFailed(any(Exception.class));
  requestQueue = Volley.newRequestQueue(RuntimeEnvironment.application);
  mockWebServer = new MockWebServer();
  mockWebServer.start();

  streamCaptor = ArgumentCaptor.forClass(InputStream.class);
}
项目:ShotsNewsApp    文件:TestLoginActivity.java   
void getImage()                                                                                 //profile pic
    {
        ImageRequest request = new ImageRequest("http://ec2-52-14-50-89.us-east-2.compute.amazonaws.com/static/userdata/"+email+"/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(TestLoginActivity.this);
        queue.add(request);
    }
项目:GitHub    文件:VolleyStreamFetcherServerTest.java   
@Before
public void setUp() throws IOException {
  MockitoAnnotations.initMocks(this);

  waitForResponseLatch = new CountDownLatch(1);
  doAnswer(new CountDown()).when(callback).onDataReady(any(InputStream.class));
  doAnswer(new CountDown()).when(callback).onLoadFailed(any(Exception.class));
  requestQueue = Volley.newRequestQueue(RuntimeEnvironment.application);
  mockWebServer = new MockWebServer();
  mockWebServer.start();

  streamCaptor = ArgumentCaptor.forClass(InputStream.class);
}
项目:Wings2K16    文件:AppController.java   
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    }

    return mRequestQueue;
}
项目:publicProject    文件:GlobalVariable.java   
/**
 * @return RequestQueue
 */
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(mContext, new OkHttpStack(new OkHttpClient()));
    }
    mRequestQueue.getCache().clear();
    return mRequestQueue;
}
项目:TreasureHunting    文件:RemoteDatabaseRespresenter.java   
public void getDataFromServer(Context context){

            queue = Volley.newRequestQueue(context);
            url = "http://10.0.2.2:8080/WebServiceForKnowHunt/KnowHuntServlet";


        JsonObjectRequest stringRequest = new JsonObjectRequest(Request.Method.GET, url, null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        try {

                            JSONArray jsonArray =  response.getJSONArray("qaList");

                            for(int i = 0; i < jsonArray.length(); i++) {

                                JSONObject json_data = jsonArray.getJSONObject(i);


                                System.out.print(json_data.toString());
                                questAndAnswDatabaseHelper.insertDataQA(json_data.getString("question"), json_data.getString("rightAnswer"),
                                        json_data.getString("optionalAnswer1"), json_data.getString("optionalAnswer2"), json_data.getString("optionalAnswer3"),
                                        0, json_data.getString("secretCode"));
                            }

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });


        queue.add(stringRequest);
    }
项目:Forager    文件:StartGame.java   
private void setComponents() {
    question = (TextView) findViewById(R.id.question);
    counter = (TextView) findViewById(R.id.counter);
    skipButton = (Button) findViewById(R.id.skipButton);
    submitButton = (Button) findViewById(R.id.Submit);

    // Instantiate the RequestQueue.
    queue = Volley.newRequestQueue(this);
    //Initialise FirebaseAuth
    firebaseAuth = FirebaseAuth.getInstance();
    databaseReference = FirebaseDatabase.getInstance().getReference();

    uid = firebaseAuth.getCurrentUser().getUid();

    readable = (CheckBox) findViewById(R.id.legibleCheckBox);

    veryToxic = findViewById(R.id.veryToxic);
    somewhatToxic = findViewById(R.id.somewhatToxic);
    notToxic = findViewById(R.id.notToxic);
    veryInsult = findViewById(R.id.veryInsult);
    somewhatInsult = findViewById(R.id.somewhatInsult);
    notInsult = findViewById(R.id.notInsult);
    veryObscene = findViewById(R.id.veryObscene);
    somewhatObscene = findViewById(R.id.somewhatObscene);
    notObscene = findViewById(R.id.notObscene);
    veryThreat = findViewById(R.id.veryThreat);
    somewhatThreat = findViewById(R.id.somewhatThreat);
    notThreat = findViewById(R.id.notThreat);
    veryIdentityHate = findViewById(R.id.veryIdentityHate);
    somewhatIdentityHate = findViewById(R.id.somewhatIdentityHate);
    notIdentityHate = findViewById(R.id.notIdentityHate);

    toxic = findViewById(R.id.toxic);
    insult = findViewById(R.id.insult);
    obscene = findViewById(R.id.obscene);
    threat = findViewById(R.id.threat);
    identityHate = findViewById(R.id.hate);

    comments = (EditText) findViewById(R.id.comments);
}
项目:Sega    文件:ProfileDetailFragment.java   
@Override
public void unLiked(LikeButton likeButton) {
    requestQueue = Volley.newRequestQueue(getContext());
    //
    StringRequest request = new StringRequest(Request.Method.POST, AppConfig.URL_FAVORITE, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            //                        Toast.makeText(getContext(),response.toString(), Toast.LENGTH_SHORT).show();
            System.out.println(response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getContext(), "Error", Toast.LENGTH_LONG).show();
        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> param = new HashMap<>();
            param.put("userrated", String.valueOf(session.getLoginId()));
            param.put("userrating", String.valueOf(seller.userid));
            return param;

        }

    };

    requestQueue.add(request);
}
项目:ShotsNewsApp    文件:SplashScreenActivity.java   
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);
    }
项目:TYT    文件:T_ContactsCompanyDetailsMoreInlandFragment.java   
@Override
public void onAfterViews() {
    mToolbar.setVisibility(View.GONE);
    REQUEST_API = getArguments().getString(AppDelegate.REQUEST_API);
    userInfoSp = MyApplication_.getInstance().getUserInfoSp();
    mRequestQueue = Volley.newRequestQueue(getActivity());
    initRecyclerView();
    initSwipeRefreshLayout();
}
项目:eBread    文件:VolleyRequest.java   
private RequestQueue getRequestQueue() {
    if (mContext == null) { return null; }
    if (mRequestQueue == null) {
        // getApplicationContext() is key, it keeps you from leaking the
        // Activity or BroadcastReceiver if someone passes one in.
        mRequestQueue = Volley.newRequestQueue(mContext.getApplicationContext());
    }
    return mRequestQueue;
}
项目:trvlr-android    文件:AppController.java   
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    }

    return mRequestQueue;
}
项目:TYT    文件:T_WarningCenter_InvoiceWarning.java   
@Override
public void onAfterViews() {
    mRequestQueue = Volley.newRequestQueue(getActivity());
    userInfoSp = MyApplication_.getInstance().getUserInfoSp();
    accountId = userInfoSp.getString(AppDelegate.ACCOUNT_ID, "");
    initRecyclerView();
    initSwipeRefreshLayout();
}
项目:TYT    文件:T_MyFund_AccountFinancingFragment.java   
@Override
public void onAfterViews() {
    mRequestQueue = Volley.newRequestQueue(getActivity());
    initBroadcastReceiver();
    initRecyclerView();
    initSwipeRefreshLayout();
}
项目:TYT    文件:T_ContactsCompanyListFragment.java   
@Override
public void onAfterViews() {
    REQUEST_API = getArguments().getString(AppDelegate.REQUEST_API);
    userInfoSp = MyApplication_.getInstance().getUserInfoSp();
    mRequestQueue = Volley.newRequestQueue(getActivity());
    initRecyclerView();
    initSwipeRefreshLayout();
}
项目:TYT    文件:T_OrderFormDetailsActivity.java   
@Override
public void onAfterViews() {
    initToolbar();
    orderId = getIntent().getIntExtra(AppDelegate.ORDER_ID, 0);
    mRequestQueue = Volley.newRequestQueue(this);
    userInfoSp = MyApplication_.getInstance().getUserInfoSp();
    showView(mProgressbar);
    onBackgrounds();
}
项目:TYT    文件:T_ApplyPaymentActivity.java   
@Override
public void onAfterViews() {
    initToolbar();
    mRequestQueue = Volley.newRequestQueue(this);  // 实例化请求队列
    initRecyclerView();
    initSwipeRefreshLayout();
    initBroadcastReceiver();
}
项目:TYT    文件:T_TitleChangeActivity.java   
@Override
public void onAfterViews() {
    initToolbar();
    mRequestQueue = Volley.newRequestQueue(this);
    userInfoSp = MyApplication_.getInstance().getUserInfoSp();
    initRecyclerView();
    showView(mProgressBar);
    onBackgrounds();
}
项目:TYT    文件:T_InvoiceInformationProductsActivity.java   
@Override
public void onAfterViews() {
    initToolbar();
    mRequestQueue = Volley.newRequestQueue(this);
    initRecyclerView();
    initSwipeRefreshLayout();
}
项目:TYT    文件:CB_ManagesSearchActivity.java   
@Override
public void onAfterViews() {
    userInfoSp = MyApplication_.getInstance().getUserInfoSp();
    accountNature = userInfoSp.getInt(AppDelegate.ACCOUNT_NATURE, -1);
    accountId = userInfoSp.getString(AppDelegate.ACCOUNT_ID, "");
    mRequestQueue = Volley.newRequestQueue(this);
    initToolbar();
    initSearchView();
    initRecyclerView();
    showHistory();
}
项目:TYT    文件:CB_ManageActivity.java   
@Override
public void onAfterViews() {
    mRequestQueue = Volley.newRequestQueue(this);
    showView(mProgressbar);
    initToolbar();
    initArguments();
    onBackgrounds();
}
项目:TYT    文件:T_AccountSearchActivity.java   
@Override
public void onAfterViews() {
    initToolbar();
    userInfoSp = MyApplication_.getInstance().getUserInfoSp();
    mRequestQueue = Volley.newRequestQueue(this);
    mListPop = new ListPopupWindow(this);
    onBackgrounds();
    initView();
}
项目:plainrequest    文件:PlainRequestQueue.java   
/**
 * Inicia uma instancia da lib PlainRequest
 *
 * @param app
 */
public void start(Application app) {
    if(context == null) {
        context = app.getApplicationContext();
        queue = Volley.newRequestQueue(context); // Criação do RequestQueue
    }
}
项目:TYT    文件:CB_ManageDetailsActivity.java   
@Override
public void onAfterViews() {
    id = getIntent().getIntExtra(AppDelegate.ID, 0);
    accountNature = MyApplication_.getInstance().getUserInfoSp().getInt(AppDelegate.ACCOUNT_NATURE, -1);
    mRequestQueue = Volley.newRequestQueue(this);
    showView(mProgressbar);
    initToolbar();
    onBackgrounds();
}
项目:TYT    文件:ModifyPasswordActivity.java   
@AfterViews
public void onAfterViews() {
    mRequestQueue = Volley.newRequestQueue(this);
    userInfoSp = MyApplication.getInstance().getUserInfoSp();
    loginPassword = userInfoSp.getString(AppDelegate.PASSWORD, "");
    initToolbar();
    initEditText();
    tv_lgName.setText("用户登录名:" + userInfoSp.getString(AppDelegate.LG_NAME, ""));
    tv_platformName.setText("登录平台名:" + MyApplication_.getInstance().getPlatFormString());
}
项目:TYT    文件:T_ContactsCompanyDetailsMoreForeignActivity.java   
@Override
public void onAfterViews() {
    initToolbar();
    rowsEntity = (T_ContactsCompanyEntity.RowsEntity) getIntent().getSerializableExtra(AppDelegate.ROWS_ENTITY);
    mRequestQueue = Volley.newRequestQueue(this);
    userInfoSp = MyApplication_.getInstance().getUserInfoSp();
    initRecyclerView();
    initSwipeRefreshLayout();
}
项目:Spitfire    文件:MainActivity.java   
@Override
protected void onStart() {
    super.onStart();
    linearLayout.removeAllViews();
    requestQueue = Volley.newRequestQueue(this);

    loadGetRequest();
    loadPostRequest();
    loadFileStreamRequest();
    loadMultipartRequest();
}
项目:FlyHttp    文件:VolleyControllerSingleton.java   
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        // getApplicationContext() is key, it keeps you from leaking the
        // Activity or BroadcastReceiver if someone passes one in.
        mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
    }
    return mRequestQueue;
}
项目:Sega    文件:ProfileDetailFragment.java   
@Override
public void liked(LikeButton likeButton) {
    requestQueue = Volley.newRequestQueue(getContext());

    StringRequest request = new StringRequest(Request.Method.POST, AppConfig.URL_FAVORITE, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            //                        Toast.makeText(getContext(),response.toString(), Toast.LENGTH_SHORT).show();
            System.out.println(response);
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getContext(), "Error", Toast.LENGTH_LONG).show();
        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> param = new HashMap<>();
            param.put("userrated", String.valueOf(session.getLoginId()));
            param.put("userrating", String.valueOf(seller.userid));
            return param;

        }

    };

    requestQueue.add(request);
}
项目:AndroidCrossPromotion    文件:VolleySingleton.java   
public RequestQueue getRequestQueue() {

        if (mRequestQueue == null) {
            mRequestQueue = Volley.newRequestQueue(mContext);
        }

        return mRequestQueue;
    }