当前位置: 首页>>代码示例>>Java>>正文


Java Response类代码示例

本文整理汇总了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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:ResponseTest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:Fdv_JsonObjectRequest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:Fdv_StringRequest.java

示例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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:Fdv_StringRequest.java

示例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();

    }
 
开发者ID:pop1234o,项目名称:BestPracticeApp,代码行数:19,代码来源:MainActivity.java

示例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));
        }
    };
}
 
开发者ID:trvlrch,项目名称:trvlr-android,代码行数:18,代码来源:BaseDrawerActivity.java

示例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);
}
 
开发者ID:JonathandelaSen,项目名称:TheMovies,代码行数:18,代码来源:MoviesTask.java

示例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);

    }
 
开发者ID:yusufcakal,项目名称:RestaurantApp,代码行数:30,代码来源:Request.java

示例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();
}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:19,代码来源:MainActivity.java

示例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();


}
 
开发者ID:pop1234o,项目名称:BestPracticeApp,代码行数:24,代码来源:MainActivity.java

示例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);
}
 
开发者ID:rakutentech,项目名称:android-perftracking,代码行数:23,代码来源:LocationStore.java

示例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);
}
 
开发者ID:AweiLoveAndroid,项目名称:HttpRequestProcessor,代码行数:17,代码来源:VolleyProcessor.java

示例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);
}
 
开发者ID:njitdev,项目名称:sa-android,代码行数:20,代码来源:AnalyticsModels.java

示例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));
}
 
开发者ID:Sayi,项目名称:RestClient,代码行数:22,代码来源:RestRequest.java

示例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) {

    }
    }));

}
 
开发者ID:ITCoders,项目名称:MobileCloudIR,代码行数:20,代码来源:MainActivity.java


注:本文中的com.android.volley.Response类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。