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); }
/** * 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; }
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); }
/** * 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; }
/** * (主线程)创建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); }
@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(); } }); }
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); }
public RequestQueue getRequestQueue() { if (mRequestQueue == null) { mRequestQueue = Volley.newRequestQueue(getApplicationContext()); } return mRequestQueue; }
private static RequestQueue getInternalQueue(Context context) { if (internalQueue == null) { synchronized (Factory.class) { if (internalQueue == null) { internalQueue = Volley.newRequestQueue(context); } } } return internalQueue; }
@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); }
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); }
/** * @return RequestQueue */ public RequestQueue getRequestQueue() { if (mRequestQueue == null) { mRequestQueue = Volley.newRequestQueue(mContext, new OkHttpStack(new OkHttpClient())); } mRequestQueue.getCache().clear(); return mRequestQueue; }
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); }
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); }
@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); }
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); }
@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(); }
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; }
@Override public void onAfterViews() { mRequestQueue = Volley.newRequestQueue(getActivity()); userInfoSp = MyApplication_.getInstance().getUserInfoSp(); accountId = userInfoSp.getString(AppDelegate.ACCOUNT_ID, ""); initRecyclerView(); initSwipeRefreshLayout(); }
@Override public void onAfterViews() { mRequestQueue = Volley.newRequestQueue(getActivity()); initBroadcastReceiver(); initRecyclerView(); initSwipeRefreshLayout(); }
@Override public void onAfterViews() { REQUEST_API = getArguments().getString(AppDelegate.REQUEST_API); userInfoSp = MyApplication_.getInstance().getUserInfoSp(); mRequestQueue = Volley.newRequestQueue(getActivity()); initRecyclerView(); initSwipeRefreshLayout(); }
@Override public void onAfterViews() { initToolbar(); orderId = getIntent().getIntExtra(AppDelegate.ORDER_ID, 0); mRequestQueue = Volley.newRequestQueue(this); userInfoSp = MyApplication_.getInstance().getUserInfoSp(); showView(mProgressbar); onBackgrounds(); }
@Override public void onAfterViews() { initToolbar(); mRequestQueue = Volley.newRequestQueue(this); // 实例化请求队列 initRecyclerView(); initSwipeRefreshLayout(); initBroadcastReceiver(); }
@Override public void onAfterViews() { initToolbar(); mRequestQueue = Volley.newRequestQueue(this); userInfoSp = MyApplication_.getInstance().getUserInfoSp(); initRecyclerView(); showView(mProgressBar); onBackgrounds(); }
@Override public void onAfterViews() { initToolbar(); mRequestQueue = Volley.newRequestQueue(this); initRecyclerView(); initSwipeRefreshLayout(); }
@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(); }
@Override public void onAfterViews() { mRequestQueue = Volley.newRequestQueue(this); showView(mProgressbar); initToolbar(); initArguments(); onBackgrounds(); }
@Override public void onAfterViews() { initToolbar(); userInfoSp = MyApplication_.getInstance().getUserInfoSp(); mRequestQueue = Volley.newRequestQueue(this); mListPop = new ListPopupWindow(this); onBackgrounds(); initView(); }
/** * 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 } }
@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(); }
@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()); }
@Override public void onAfterViews() { initToolbar(); rowsEntity = (T_ContactsCompanyEntity.RowsEntity) getIntent().getSerializableExtra(AppDelegate.ROWS_ENTITY); mRequestQueue = Volley.newRequestQueue(this); userInfoSp = MyApplication_.getInstance().getUserInfoSp(); initRecyclerView(); initSwipeRefreshLayout(); }
@Override protected void onStart() { super.onStart(); linearLayout.removeAllViews(); requestQueue = Volley.newRequestQueue(this); loadGetRequest(); loadPostRequest(); loadFileStreamRequest(); loadMultipartRequest(); }
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; }
@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); }
public RequestQueue getRequestQueue() { if (mRequestQueue == null) { mRequestQueue = Volley.newRequestQueue(mContext); } return mRequestQueue; }