public class HttpUtils {
private static HttpUtils httpUtils;
private HttpUtils(){}
public static HttpUtils getInstance(){
if (httpUtils==null){
return new HttpUtils();
}
return httpUtils;
}
public void getDate(String strUrl, final CallBack back, final Class bean, final HashMap<String,String> map){
RequestQueue requestQueue = Volley.newRequestQueue(App.context);
StringRequest stringRequest = new StringRequest(StringRequest.Method.POST, strUrl, new Response.Listener() {
@Override
public void onResponse(String response) {
Gson gson = new Gson();
B b = gson.fromJson(response, bean);
back.ok(b);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
return map;
}
};
requestQueue.add(stringRequest);
}
public interface CallBack<B>{
void ok(B b);
}
public boolean isNetWork(Context context){
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager!=null){
NetworkInfo info = manager.getActiveNetworkInfo();
return info.isAvailable();
}
return false;
}
}