当前位置: 首页>>代码示例>>Java>>正文


Java Volley类代码示例

本文整理汇总了Java中com.android.volley.toolbox.Volley的典型用法代码示例。如果您正苦于以下问题:Java Volley类的具体用法?Java Volley怎么用?Java Volley使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Volley类属于com.android.volley.toolbox包,在下文中一共展示了Volley类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPhone

import com.android.volley.toolbox.Volley; //导入依赖的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: volleySyncRequest

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:IelloDevTeam,项目名称:IelloAndroidApp,代码行数:25,代码来源:HelperRete.java

示例3: requestPosts

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
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);
}
 
开发者ID:jamesddube,项目名称:LaravelNewsApp,代码行数:25,代码来源:rssRequest.java

示例4: volleySyncRequest

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:IelloDevTeam,项目名称:IelloAndroidAdminApp,代码行数:25,代码来源:HelperRete.java

示例5: requestVolley

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
/**
 * (主线程)创建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);
}
 
开发者ID:pop1234o,项目名称:BestPracticeApp,代码行数:36,代码来源:MainActivity.java

示例6: onCreate

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
@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();
            }
        });
    }
 
开发者ID:henrymorgen,项目名称:android-advanced-light,代码行数:20,代码来源:MainActivity.java

示例7: SendRequest

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
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);

}
 
开发者ID:zhirunn,项目名称:CompassDemo,代码行数:22,代码来源:UserSearchActivity.java

示例8: getRequestQueue

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(getApplicationContext());
    }

    return mRequestQueue;
}
 
开发者ID:huluhive,项目名称:android-volley-file-upload,代码行数:8,代码来源:MyApplication.java

示例9: getInternalQueue

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
private static RequestQueue getInternalQueue(Context context) {
  if (internalQueue == null) {
    synchronized (Factory.class) {
      if (internalQueue == null) {
        internalQueue = Volley.newRequestQueue(context);
      }
    }
  }
  return internalQueue;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:11,代码来源:VolleyUrlLoader.java

示例10: setUp

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
@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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:VolleyStreamFetcherServerTest.java

示例11: getImage

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
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);
    }
 
开发者ID:goutham-kalikrishna,项目名称:ShotsNewsApp,代码行数:31,代码来源:TestLoginActivity.java

示例12: getRequestQueue

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
/**
 * @return RequestQueue
 */
public RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        mRequestQueue = Volley.newRequestQueue(mContext, new OkHttpStack(new OkHttpClient()));
    }
    mRequestQueue.getCache().clear();
    return mRequestQueue;
}
 
开发者ID:wangzhaosheng,项目名称:publicProject,代码行数:11,代码来源:GlobalVariable.java

示例13: getDataFromServer

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
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);
    }
 
开发者ID:LenaShervarly,项目名称:TreasureHunting,代码行数:40,代码来源:RemoteDatabaseRespresenter.java

示例14: setComponents

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
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);
}
 
开发者ID:moizalicious,项目名称:Forager,代码行数:41,代码来源:StartGame.java

示例15: unLiked

import com.android.volley.toolbox.Volley; //导入依赖的package包/类
@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);
}
 
开发者ID:sega4revenge,项目名称:Sega,代码行数:30,代码来源:ProfileDetailFragment.java


注:本文中的com.android.volley.toolbox.Volley类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。