本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
});
}
示例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);
}
示例8: getRequestQueue
import com.android.volley.toolbox.Volley; //导入依赖的package包/类
public RequestQueue getRequestQueue() {
if (mRequestQueue == null) {
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
}
return mRequestQueue;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}