本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}