本文整理汇总了Java中com.android.volley.toolbox.StringRequest类的典型用法代码示例。如果您正苦于以下问题:Java StringRequest类的具体用法?Java StringRequest怎么用?Java StringRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringRequest类属于com.android.volley.toolbox包,在下文中一共展示了StringRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPhone
import com.android.volley.toolbox.StringRequest; //导入依赖的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: 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);
}
示例3: post
import com.android.volley.toolbox.StringRequest; //导入依赖的package包/类
/**
* 根据地址和请求参数 发送POST请求
* @param url 地址服务器地址
* @param listener 数据加载回调接口
* @param params 请求参数
*/
public void post(String url, final Fdv_CallBackListener<String> listener,Map<String,String> params){
StringRequest stringRequest=new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if(listener!=null){
listener.onSuccessResponse(response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if(listener!=null){
listener.onErrorResponse(error);
}
}
});
addRequest(stringRequest,params);
}
示例4: load
import com.android.volley.toolbox.StringRequest; //导入依赖的package包/类
public void load(String url, final OnStringListener listener) {
StringRequest request = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
listener.onSuccess(s);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
listener.onError(volleyError);
}
});
request.setRetryPolicy(new DefaultRetryPolicy(DefaultRetryPolicy.DEFAULT_TIMEOUT_MS,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
VolleySingleton.getVolleySingleton(context).addToRequestQueue(request);
}
示例5: execute
import com.android.volley.toolbox.StringRequest; //导入依赖的package包/类
public void execute() {
final String url = URL + "/sync";
isSyncing = true;
StringRequest req = new StringRequest(Request.Method.POST, url, this, this) {
@Override
public HashMap<String, String> getHeaders() {
return getDefaultHeaders();
}
@Override
public byte[] getBody() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("username", mUsername);
params.put("lastSyncedTime", String.valueOf(mLastSyncedTimeEpoch));
return new JSONObject(params).toString().getBytes();
}
};
req.setRetryPolicy(new DefaultRetryPolicy(
ASYNC_CONNECTION_EXTENDED_TIMEOUT,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
0));
VolleyRequestQueue.getInstance().addToRequestQueue(req);
}
示例6: get
import com.android.volley.toolbox.StringRequest; //导入依赖的package包/类
/**
* get request
*
* @param url
* @param callback
*/
@Override
public void get(String url, final IRequestCallback callback) {
StringRequest request = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
callback.onSuccess(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
callback.onFailure(error);
}
});
mQueue.add(request);
}
示例7: volleyGetStringRequest
import com.android.volley.toolbox.StringRequest; //导入依赖的package包/类
private String volleyGetStringRequest() {
StringRequest request = new StringRequest(Request.Method.GET, Constant.JUHE_URL_GET,
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();
}
});
request.setTag(STRING_GET_TAG);
MyApplication.getHttpQueues().add(request);
return request.getTag().toString();
}
示例8: onErrorResponse
import com.android.volley.toolbox.StringRequest; //导入依赖的package包/类
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "onErrorResponse: " + error.toString());
findViewById(R.id.articleLoader).setVisibility(View.GONE);
ConnectivityManager cm = (ConnectivityManager) getBaseContext().getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm != null) {
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if (activeNetwork == null || !activeNetwork.isConnectedOrConnecting()) {
// Display icon
findViewById(R.id.noNetwork).setVisibility(View.VISIBLE);
// Display permanent message
Snackbar.make(findViewById(R.id.coordinatorArticle), getString(R.string.error_no_connection), Snackbar.LENGTH_INDEFINITE)
.setAction(getString(R.string.error_no_connection_retry), new View.OnClickListener() {
@Override
public void onClick(View v) {
REQUEST_QUEUE.add(new StringRequest(Request.Method.GET, shareLink, articleReceived, errorResponse));
}
}).show();
}
}
}
示例9: get
import com.android.volley.toolbox.StringRequest; //导入依赖的package包/类
@Override
public void get(String url, Map<String, Object> params, final ICallBack callback) {
StringRequest stringRequest = new StringRequest(Request.Method.GET,
url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
callback.onSuccess(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
callback.onFailed(volleyError.toString());
}
});
mQueue.add(stringRequest);
}
示例10: post
import com.android.volley.toolbox.StringRequest; //导入依赖的package包/类
@Override
public void post(String url, Map<String, Object> params, final ICallBack callback) {
StringRequest stringRequest = new StringRequest(Request.Method.POST,
url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
callback.onSuccess(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
callback.onFailed(volleyError.toString());
}
});
mQueue.add(stringRequest);
}
示例11: getRequest
import com.android.volley.toolbox.StringRequest; //导入依赖的package包/类
protected void getRequest()
{
StringRequest stringGetRequest = new StringRequest(Request.Method.GET, UserPref.getNewfolderUrl(),
new Response.Listener<String>(){
@Override
public void onResponse(String response)
{
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error)
{
Toast.makeText(ApplyActivity.this,error.toString(),Toast.LENGTH_SHORT).show();
}
});
requestQueue.add(stringGetRequest);
}
示例12: execute
import com.android.volley.toolbox.StringRequest; //导入依赖的package包/类
public void execute() {
final String url = URL + "/remind";
StringRequest req = new StringRequest(Request.Method.POST, url, this, this) {
@Override
public HashMap<String, String> getHeaders() {
return getDefaultHeaders();
}
@Override
public byte[] getBody() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("fromUsername", mUsername);
params.put("toUsername", mToUsername);
params.put("guid", mGuid);
params.put("isRemindingRef", isRemindingRef ? "1" : "0");
return new JSONObject(params).toString().getBytes();
}
};
req.setRetryPolicy(new DefaultRetryPolicy(
ASYNC_CONNECTION_NORMAL_TIMEOUT,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
0));
VolleyRequestQueue.getInstance().addToRequestQueue(req);
}
示例13: execute
import com.android.volley.toolbox.StringRequest; //导入依赖的package包/类
public void execute() {
final String url = URL + "/upvote";
StringRequest req = new StringRequest(Request.Method.POST, url, this, this) {
@Override
public HashMap<String, String> getHeaders() {
return getDefaultHeaders();
}
@Override
public byte[] getBody() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("username", mUsername);
params.put("guid", mGuid);
return new JSONObject(params).toString().getBytes();
}
};
req.setRetryPolicy(new DefaultRetryPolicy(
ASYNC_CONNECTION_NORMAL_TIMEOUT,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
0));
VolleyRequestQueue.getInstance().addToRequestQueue(req);
}
示例14: execute
import com.android.volley.toolbox.StringRequest; //导入依赖的package包/类
public void execute() {
final String url = URL + "/register";
isRegistering = true;
StringRequest req = new StringRequest(Request.Method.POST, url, this, this) {
@Override
public Map<String, String> getHeaders() {
return getDefaultHeaders();
}
@Override
public byte[] getBody() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("username", mUsername);
params.put("device", "android");
params.put("pushID", mPushID);
return new JSONObject(params).toString().getBytes();
}
};
req.setRetryPolicy(new DefaultRetryPolicy(
ASYNC_CONNECTION_EXTENDED_TIMEOUT,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
0));
VolleyRequestQueue.getInstance().addToRequestQueue(req);
}
示例15: SendRequest
import com.android.volley.toolbox.StringRequest; //导入依赖的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);
}