本文整理汇总了Java中com.android.volley.Response类的典型用法代码示例。如果您正苦于以下问题:Java Response类的具体用法?Java Response怎么用?Java Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Response类属于com.android.volley包,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: publicMethods
import com.android.volley.Response; //导入依赖的package包/类
@Test
public void publicMethods() throws Exception {
// Catch-all test to find API-breaking changes.
assertNotNull(Response.class.getMethod("success", Object.class, Cache.Entry.class));
assertNotNull(Response.class.getMethod("error", VolleyError.class));
assertNotNull(Response.class.getMethod("isSuccess"));
assertNotNull(Response.Listener.class.getDeclaredMethod("onResponse", Object.class));
assertNotNull(Response.ErrorListener.class.getDeclaredMethod("onErrorResponse",
VolleyError.class));
assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class,
boolean.class, long.class));
assertNotNull(NetworkResponse.class.getConstructor(int.class, byte[].class, Map.class,
boolean.class));
assertNotNull(NetworkResponse.class.getConstructor(byte[].class));
assertNotNull(NetworkResponse.class.getConstructor(byte[].class, Map.class));
}
示例2: get
import com.android.volley.Response; //导入依赖的package包/类
/**
* 请求返回JSONObject对象 Get请求 无参数,或者get请求的参数直接拼接在URL上面
* @param url 请求地址
* @param listener 数据回调接口
*/
public void get(String url, final Fdv_CallBackListener<JSONObject> listener){
JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
if(listener!=null){
listener.onSuccessResponse(response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if(listener!=null){
listener.onErrorResponse(error);
}
}
});
addRequest(jsonObjectRequest);
}
示例3: get
import com.android.volley.Response; //导入依赖的package包/类
/**
* 普通文本等信息 Get请求 无参数,或者get请求的参数直接拼接在URL上面
* @param url 请求的地址
* @param listener 数据请求返回接口回调
*/
public void get(String url, final Fdv_CallBackListener<String> listener){
StringRequest stringRequest=new StringRequest(Request.Method.GET, 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);
}
示例4: post
import com.android.volley.Response; //导入依赖的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);
}
示例5: requestOkHttp
import com.android.volley.Response; //导入依赖的package包/类
/**
* 缓存
*/
private void requestOkHttp() {
new OkHttpClient.Builder().addInterceptor(new Interceptor() {
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
okhttp3.Request request = chain.request();
// chain.request().newBuilder().addHeader().build()
okhttp3.Response response = chain.proceed(request);
return response;
}
}).cache(new okhttp3.Cache(getCacheDir(), 5 * 1024 * 1024)).build();
okhttp3.Request request_forceNocache = new okhttp3.Request.Builder().cacheControl(new CacheControl.Builder().noCache().build()).url("").build();
okhttp3.Request request_forceCache = new okhttp3.Request.Builder().cacheControl(new CacheControl.Builder().maxAge(0, TimeUnit.SECONDS).build()).url("").build();
}
示例6: leaveChatSuccess
import com.android.volley.Response; //导入依赖的package包/类
private Response.Listener leaveChatSuccess() {
return new Response.Listener() {
@Override
public void onResponse(Object response) {
AppController controller = AppController.getInstance();
Chat bo = controller.getCurrentActiveChat();
controller.removeChat(bo.getChatId(), controller.getCurrentActiveChatType());
finish();
// Reset current active chat.
controller.setCurrentActiveChat(bo.getChatType(), null);
// Show find connection after leaving a chat room.
startActivity(new Intent(getApplicationContext(), FindConnectionActivity.class));
}
};
}
示例7: requestGetMovie
import com.android.volley.Response; //导入依赖的package包/类
private static void requestGetMovie(String url, final GetMovieCallback callback,
Activity activity) {
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
callback.successGetMovie(MoviesMapping.getMovieFromJson(response));
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
callback.errorGetMovie();
}
});
VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
示例8: requestVolleyAuth
import com.android.volley.Response; //导入依赖的package包/类
public void requestVolleyAuth(final VolleyCallback callback, final String username, final String password){
final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(requestMethod, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
callback.onSuccesAuth(response);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(context, String.valueOf(error), Toast.LENGTH_SHORT).show();
}
}){
@Override
public byte[] getBody() {
HashMap<String, String> params = new HashMap<String, String>();
params.put("username", username);
params.put("password", password);
return new JSONObject(params).toString().getBytes();
}
};
requestQueue.add(jsonObjectRequest);
}
示例9: volleyGetJsonObjectRequest
import com.android.volley.Response; //导入依赖的package包/类
private String volleyGetJsonObjectRequest() {
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, Constant.JUHE_URL_GET, null, // 用post方式时,需更改为带请求参数的Object
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Toast.makeText(MainActivity.this, response.toString(), 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(JSON_OBJECT_GET_TAG);
MyApplication.getHttpQueues().add(request);
return request.getTag().toString();
}
示例10: requestOkHttpGet
import com.android.volley.Response; //导入依赖的package包/类
private void requestOkHttpGet() {
new Thread(new Runnable() {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void run() {
if (okHttpClient == null) {
okHttpClient = new OkHttpClient();
}
okhttp3.Request.Builder builder = new okhttp3.Request.Builder();
okhttp3.Request request = builder.url("http://www.google.com").build();
//必须在这定义
try (okhttp3.Response response = okHttpClient.newCall(request).execute()) {
String s = response.body().string();//注意这里是string()不是toString();
Log.i(TAG, "requestOkHttpGet: " + s);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
}
示例11: loadLocationFromApi
import com.android.volley.Response; //导入依赖的package包/类
private void loadLocationFromApi() {
if (subscriptionKey == null) {
Log.d(TAG, "Cannot read metadata `com.rakuten.tech.mobile.perf.SubscriptionKey` from "
+ "manifest automated performance tracking will not work.");
}
new GeoLocationRequest(urlPrefix,
subscriptionKey,
new Response.Listener<GeoLocationResult>() {
@Override
public void onResponse(GeoLocationResult newLocation) {
LocationData locationData = new LocationData(newLocation.getCountryName(),
newLocation.getRegionName());
writeLocationToCache(locationData);
getObservable().publish(locationData);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Error loading location", error);
}
}).queue(requestQueue);
}
示例12: post
import com.android.volley.Response; //导入依赖的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);
}
示例13: sendStartEvent
import com.android.volley.Response; //导入依赖的package包/类
public static void sendStartEvent(String installationID) {
// Prepare parameters
Map<String, String> map = new HashMap<>();
map.put("installation_id", installationID);
map.put("school", SAConfig.schoolIdentifier);
map.put("client_version", BuildConfig.VERSION_NAME);
map.put("device_info", SAUtils.getDeviceModel());
JSONObject params = new JSONObject(map);
// Make request
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, baseURL + "/start", params, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {}
});
SAGlobal.sharedRequestQueue.add(jsonObjectRequest);
}
示例14: parseNetworkResponse
import com.android.volley.Response; //导入依赖的package包/类
@Override
protected Response<RemoteResponse> parseNetworkResponse(NetworkResponse response) {
RemoteResponse remoteResponse = new RemoteResponse();
if (null != response) {
try {
remoteResponse.setStatusCode(response.statusCode);
remoteResponse.setResponseMessage(HttpStatusNoteMap.getNote(response.statusCode));
remoteResponse.setInterval(response.networkTimeMs);
remoteResponse.setHeaders(response.headers);
String str = new String(response.data, HttpHeaderParser.parseCharset(response.headers, "utf-8"));
remoteResponse.setResponse(str);
} catch (UnsupportedEncodingException e) {
remoteResponse.setResponse(e.getMessage());
}
} else {
remoteResponse.setStatusCode(-1);
remoteResponse.setResponseMessage("Error");
}
return Response.success(remoteResponse, HttpHeaderParser.parseCacheHeaders(response));
}
示例15: requestServer
import com.android.volley.Response; //导入依赖的package包/类
public void requestServer(final String url) {
queue.add(new StringRequest(Request.Method.GET, url+"/ping", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
sharedPref = context.getSharedPreferences(
"preference_file", Context.MODE_PRIVATE);
boolean dataLoaded = sharedPref.getBoolean("IsDataLoaded", false);
if (!dataLoaded){
downloadFiles(url);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}));
}