本文整理汇总了Java中com.android.volley.toolbox.StringRequest.setTag方法的典型用法代码示例。如果您正苦于以下问题:Java StringRequest.setTag方法的具体用法?Java StringRequest.setTag怎么用?Java StringRequest.setTag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.android.volley.toolbox.StringRequest
的用法示例。
在下文中一共展示了StringRequest.setTag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
public void check(final Callback callback) {
mCallback = callback;
StringRequest request = new StringRequest(Request.Method.GET, UPDATE_URL, this, this);
request.setRetryPolicy(new DefaultRetryPolicy(mTimeOut, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
request.setTag("update-check");
request.setShouldCache(false);
mRequestQueue.add(request);
}
示例2: requestVolley
import com.android.volley.toolbox.StringRequest; //导入方法依赖的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);
}
示例3: startDoubanCache
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
/**
* 网络请求豆瓣精选的内容主体并储存
* @param id 消息对应的id
*/
private void startDoubanCache(final int id) {
Cursor cursor = db.query("Douban", null, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
if ((cursor.getInt(cursor.getColumnIndex("douban_id")) == id)
&& (cursor.getString(cursor.getColumnIndex("douban_content")).equals(""))) {
StringRequest request = new StringRequest(Api.DOUBAN_ARTICLE_DETAIL + id, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
ContentValues values = new ContentValues();
values.put("douban_content", s);
db.update("Douban", values, "douban_id = ?", new String[] {String.valueOf(id)});
values.clear();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
});
request.setTag(TAG);
VolleySingleton.getVolleySingleton(CacheService.this).getRequestQueue().add(request);
}
} while (cursor.moveToNext());
}
cursor.close();
}
示例4: startGuokrCache
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
/**
* 网络请求果壳的消息内容主体并存储
* @param id 对应的id
*/
private void startGuokrCache(final int id) {
Cursor cursor = db.query("Guokr", null, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
if ((cursor.getInt(cursor.getColumnIndex("guokr_id")) == id)
&& (cursor.getString(cursor.getColumnIndex("guokr_content")).equals(""))) {
StringRequest request = new StringRequest(Api.GUOKR_ARTICLE_LINK_V1 + id, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
ContentValues values = new ContentValues();
values.put("guokr_content", s);
db.update("Guokr", values, "guokr_id = ?", new String[] {String.valueOf(id)});
values.clear();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
});
request.setTag(TAG);
VolleySingleton.getVolleySingleton(CacheService.this).getRequestQueue().add(request);
}
} while (cursor.moveToNext());
}
cursor.close();
}
示例5: loadPhoneNumberInfo
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
@Override
public void loadPhoneNumberInfo(final String phoneNumber, final OnQueryPhoneNumberListener listener) {
mQueryPhoneNumberHashMap = PhoneNumberInfoLab.get().getPhoneNumberInfoHashMap();
PhoneNumberInfo phoneNumberInfo = mQueryPhoneNumberHashMap.get(phoneNumber);
if (phoneNumberInfo == null) {
StringRequest request = new StringRequest(Request.Method.POST, Constant.JUHE_URL_POST,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i(TAG, response);
PhoneNumberInfo pni = JSONParser.parseJSON(response);
mQueryPhoneNumberHashMap.put(phoneNumber, pni);
listener.onSuccess(pni);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
listener.onError(error.toString());
}
}){
/*
重写getParams()
用户在Volley中使用post方式请求数据中参数的传递
*/
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> hashMap = new HashMap<>();
hashMap.put("phone", phoneNumber);
hashMap.put("key", Constant.JUHE_API_KEY);
return hashMap;
}
};
request.setTag(Constant.VOLLEY_TAG); //设置标签
MyApplication.getHttpQueues().add(request);//加入请求队列
} else {
listener.onSuccess(phoneNumberInfo); // 若hashMap中已经有过记录,则直接显示
}
}
示例6: volleyPostStringRequest
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
private String volleyPostStringRequest() {
StringRequest request = new StringRequest(Request.Method.POST, Constant.JUHE_URL_POST,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(MainActivity.this, response, Toast.LENGTH_SHORT).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
}
}){
/*
getParams()
用户在Volley中使用post方式请求数据中参数的传递
*/
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> hashMap = new HashMap<>();
hashMap.put("phone", "13429667914");
hashMap.put("key", "562609042fbd47baa063b1a2c4637758");
return hashMap;
}
};
request.setTag(STRING_POST_TAG);
MyApplication.getHttpQueues().add(request);
return request.getTag().toString();
}
示例7: RequestGet
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
public static void RequestGet(Context context, String url, String tag, VolleyInterface volleyInterface) {
MyApplication.getHttpQueues().cancelAll(tag); // 先清空请求队列,防止出现重复的请求消耗内存
sStringRequest = new StringRequest(Request.Method.GET, url, volleyInterface.loadingListener(), volleyInterface.errorListener());
sStringRequest.setTag(tag);
MyApplication.getHttpQueues().add(sStringRequest);
MyApplication.getHttpQueues().start();
}
示例8: RequestPost
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
public static void RequestPost(Context context, String url, String tag, Map<String, String> params, VolleyInterface volleyInterface) {
MyApplication.getHttpQueues().cancelAll(tag);
sStringRequest = new StringRequest(url, volleyInterface.loadingListener(), volleyInterface.errorListener()){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return super.getParams();
}
};
sStringRequest.setTag(tag);
MyApplication.getHttpQueues().add(sStringRequest);
MyApplication.getHttpQueues().start();
}
示例9: startDoubanCache
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
/**
* 网络请求豆瓣精选的内容主体并储存
*
* @param id 消息对应的id
*/
private void startDoubanCache(final int id) {
Cursor cursor = db.query("Douban", null, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
if ((cursor.getInt(cursor.getColumnIndex("douban_id")) == id)
&& (cursor.getString(cursor.getColumnIndex("douban_content")).equals(""))) {
StringRequest request = new StringRequest(Api.DOUBAN_ARTICLE_DETAIL + id, new Response
.Listener<String>() {
@Override
public void onResponse(String s) {
ContentValues values = new ContentValues();
values.put("douban_content", s);
db.update("Douban", values, "douban_id = ?", new String[]{String.valueOf(id)});
values.clear();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
});
request.setTag(TAG);
VolleySingleton.getVolleySingleton(CacheService.this).getRequestQueue().add(request);
}
} while (cursor.moveToNext());
}
cursor.close();
}
示例10: downloadNotification
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
private void downloadNotification() {
StringRequest strReq = new StringRequest(Request.Method.POST,
AppConfig.URL_GETNOTIFICATION, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jObj = new JSONObject(response);
JSONArray feedArray = jObj.getJSONArray("rate");
adapter = new ItemsAdapter(items);
for (int i = 0; i < feedArray.length(); i++) {
final JSONObject feedObj = (JSONObject) feedArray.get(i);
//add product to list product
items.add(new Item(feedObj.getString("text")));
}
recyclerView.setAdapter(adapter);
} catch (Exception ex) {
// JSON parsing error
ex.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<>();
params.put("userid", String.valueOf(session.getLoginId()));
return params;
}
};
strReq.setTag(this.getClass().getName());
VolleySingleton.getInstance(getApplicationContext()).requestQueue.add(strReq);
}
示例11: RegisterStep1Request
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
/**
* 注册第一步——检查手机号是否已注册
*
* @param button Loading Button
* @param activity Register Activity
* @param phoneNumber 手机号码
*/
public static void RegisterStep1Request(final LoadingButton button,
final RegisterActivity activity, final String phoneNumber) {
//请求地址
String url = HttpRequestUtils.SERVER_ROOT + "iReading/*";
String tag = "RegisterByPhoneNumberStep1";
//取得请求队列
RequestQueue requestQueue = MyApplication.getRequestQueue();
//防止重复请求,所以先取消tag标识的请求队列
requestQueue.cancelAll(tag);
//创建StringRequest,定义字符串请求的请求方式为POST(省略第一个参数会默认为GET方式)
final StringRequest request = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = (JSONObject) new JSONObject(response).get("params");
String result = jsonObject.getString("IsNew");
if (result.equals("true")) {
button.loadingSuccessful();
} else {
button.loadingFailed();
activity.showToast("该手机号已经被注册,验证手机号后可直接登录");
}
} catch (JSONException e) {
activity.showToast("网络请求发生错误,稍后请重试");
button.loadingFailed();
Log.e("TAG", e.getMessage(), e);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
activity.showToast("网络请求发生错误,稍后请重试");
button.loadingFailed();
Log.e("TAG", error.getMessage(), error);
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("RequestType", "Register");
params.put("RegisterType", "RegisterByPhoneNumber");
params.put("RegisterStep", "1");
params.put("PhoneNumber", phoneNumber);
return params;
}
};
//设置Tag标签
request.setTag(tag);
//将请求添加到队列中
requestQueue.add(request);
}
示例12: downloadRate
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
private void downloadRate() {
commentslist.clear();
StringRequest strReq = new StringRequest(Request.Method.POST,
AppConfig.URL_RATEDETAIL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jObj = new JSONObject(response);
JSONArray feedArray = jObj.getJSONArray("rate");
ratee = new Rate();
for (int i = 0; i < feedArray.length(); i++) {
final JSONObject feedObj = (JSONObject) feedArray.get(i);
System.out.println(feedObj);
//add product to list product
//add product to list products
//add product to sqlite
switch (feedObj.getInt("point")) {
case 1:
ratee.onestar +=1;
break;
case 2:
ratee.twostar +=1;
break;
case 3:
ratee.threestar +=1;
break;
case 4:
ratee.fourstar+=1;
break;
case 5:
ratee.fivestar +=1;
break;
}
favoritecount = jObj.getString("count");
Comments comment = new Comments(feedObj.getString("userid"), feedObj.getString("username"),feedObj.getString("time"),
feedObj.getString("contentcomment"), feedObj.getString("userpic"), feedObj.getString("point"));
commentslist.add(comment);
}
onDownloadRateSuccessful();
} catch (Exception ex) {
// JSON parsing error
ex.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<>();
params.put("userid", sellerid + "");
return params;
}
};
strReq.setTag(this.getClass().getName());
VolleySingleton.getInstance(getActivity()).requestQueue.add(strReq);
}
示例13: downloadproductDetails
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
private void downloadproductDetails(final String id) {
String urlToDownload = AppConfig.URL_PRODUCTDETAIL;
StringRequest strReq = new StringRequest(Request.Method.POST,
urlToDownload, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("ok", "Login Response: " + response);
try {
JSONObject jObj = new JSONObject(response);
JSONObject feedObj = jObj.getJSONObject("product");
ArrayList<String> productimg = new ArrayList<>(Arrays.asList(feedObj.getString("productimage").split(",")));
//add product to list products
product = new Product(feedObj.getInt("productid"),
feedObj.getString("productname"),
feedObj.getLong("price") / rate,
feedObj.getInt("userid"),
feedObj.getString("username"),
feedObj.getString("categoryname"),
feedObj.getString("productaddress"),
feedObj.getString("areaproduct"),
feedObj.getString("productstatus"),
productimg,
feedObj.getString("productdate"),
feedObj.getString("description"),
feedObj.getString("sharecount"),
Double.parseDouble(feedObj.getString("lat")),
Double.parseDouble(feedObj.getString("lot"))
);
seller = new User();
seller.userid = Integer.parseInt(feedObj.getString("userid"));
seller.setEmail(feedObj.getString("email"));
seller.setPhone(feedObj.getString("phone"));
seller.userpic = (feedObj.getString("userpic"));
seller.count = feedObj.getString("count");
if(feedObj.getString("rate").equals("null"))
seller.rate = "0";
else
{
seller.rate = (double) Math.round(Double.parseDouble(feedObj.getString("rate")) * 10) / 10 + "";
}
point = feedObj.getString("point");
favorite = feedObj.getString("favorite");
onDownloadSuccessful();
} catch (JSONException e) {
// JSON error
e.printStackTrace();
onDownloadFailed();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
onDownloadFailed();
error.printStackTrace();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<>();
params.put("productid", id);
params.put("userrated", session.getLoginId()+"");
params.put("userrating", sellerid);
return params;
}
};
strReq.setTag(this.getClass().getName());
VolleySingleton.getInstance(getActivity()).requestQueue.add(strReq);
}
示例14: downloadRate
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
private void downloadRate() {
StringRequest strReq = new StringRequest(Request.Method.POST,
AppConfig.URL_RATEDETAILPROFILE, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jObj = new JSONObject(response);
JSONArray feedArray = jObj.getJSONArray("rate");
ratee = new Rate();
for (int i = 0; i < feedArray.length(); i++) {
final JSONObject feedObj = (JSONObject) feedArray.get(i);
//add product to list product
switch (feedObj.getInt("point")) {
case 1:
ratee.onestar = Integer.parseInt(feedObj.getString("count"));
break;
case 2:
ratee.twostar = Integer.parseInt(feedObj.getString("count"));
break;
case 3:
ratee.threestar = Integer.parseInt(feedObj.getString("count"));
break;
case 4:
ratee.fourstar = Integer.parseInt(feedObj.getString("count"));
break;
case 5:
ratee.fivestar = Integer.parseInt(feedObj.getString("count"));
break;
}
}
Log.e("favorites", response);
rate1 = jObj.getString("rate1");
point1 = jObj.getString("count");
countfavorites = jObj.getString("countfavorites");
Log.e("RATEOK", "rate: " + rate1 + " " + "point: " + point1);
onDownloadRateSuccessful();
onDownloadSuccessful();
} catch (Exception ex) {
// JSON parsing error
ex.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<>();
params.put("userid", sellerid + "");
return params;
}
};
strReq.setTag(this.getClass().getName());
VolleySingleton.getInstance(getActivity()).requestQueue.add(strReq);
}
示例15: downloadproductDetails
import com.android.volley.toolbox.StringRequest; //导入方法依赖的package包/类
private void downloadproductDetails(final String id) {
String urlToDownload = AppConfig.URL_PRODUCTDETAIL;
StringRequest strReq = new StringRequest(Request.Method.POST,
urlToDownload, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("ok", "Login Response: " + response);
try {
JSONObject jObj = new JSONObject(response);
JSONObject feedObj = jObj.getJSONObject("product");
ArrayList<String> productimg = new ArrayList<>(Arrays.asList(feedObj.getString("productimage").split(",")));
//add product to list products
product = new Product(feedObj.getInt("productid"),
feedObj.getString("productname"),
feedObj.getLong("price") / rate,
feedObj.getInt("userid"),
feedObj.getString("username"),
feedObj.getString("categoryname"),
feedObj.getString("productaddress"),
feedObj.getString("areaproduct"),
feedObj.getString("productstatus"),
productimg,
feedObj.getString("productdate"),
feedObj.getString("description"),
feedObj.getString("sharecount"),
Double.parseDouble(feedObj.getString("lat")),
Double.parseDouble(feedObj.getString("lot"))
);
seller = new User();
seller.setEmail(feedObj.getString("email"));
seller.setPhone(feedObj.getString("phone"));
point = feedObj.getString("point");
// JSONArray feedArray = feedObj.getJSONArray("comments");
// commentslist.clear();
// for (int i = 0; i < feedArray.length(); i++) {
// final JSONObject feedComment = (JSONObject) feedArray.get(i);
// //add product to list products
// Comments comment = new Comments(feedComment.getString("userid"), feedComment.getString("username"), feedComment.getString("productid"), feedComment.getString("time"),
// feedComment.getString("contentcomment"), feedComment.getString("userpic"), feedComment.getString("rate"));
// commentslist.add(comment);
// //add product to sqlite
// }
onDownloadSuccessful();
} catch (JSONException e) {
// JSON error
e.printStackTrace();
onDownloadFailed();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
onDownloadFailed();
error.printStackTrace();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params;
params = new HashMap<String, String>();
params.put("productid", id);
params.put("userrated", String.valueOf(session.getLoginId()));
params.put("userrating", userid);
return params;
}
};
strReq.setTag(this.getClass().getName());
VolleySingleton.getInstance(getActivity()).requestQueue.add(strReq);
}