Java 类com.android.volley.request.StringRequest 实例源码

项目:TamTime    文件:ReportEvent.java   
public void confirmReport(final Context context, final int reportId) {
    Map<String,String> params = new HashMap<String, String>();
    params.put("report_id", reportId + "");

    StringRequest sr = new StringRequest(
            Request.Method.POST,
            CONFIRM_REPORT,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Integer result = Integer.parseInt(response);
                    Log.d(TAG, "REPONSE:" + response + "|");
                    Toast.makeText(context, context.getResources().getStringArray(R.array.confirm_status)[result], Toast.LENGTH_SHORT).show();
                    update();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d(TAG, "Error: " + error.getMessage());
                }
            }) {
    };
    sr.setParams(params);
    VolleyApp.getInstance(context).addToRequestQueue(sr);
}
项目:DE-MVP-Clean    文件:SentenceDataRepository.java   
public NetworkResponse getTodaysSentenceResponse() {
    StringRequest request = new StringRequest(Request.Method.GET, URL_ICIBA, null, null);
    request.setRetryPolicy(DEVolley.getInstance().getDefaultRetryPolicy(2));
    request.setTag("fetchTodaysSentence");
    DEVolley.getInstance().getRequestTickle().add(request);
    // sync get
    NetworkResponse response = DEVolley.getInstance().getRequestTickle().start();
    return response;
}
项目:TamTime    文件:ReportEvent.java   
public void sendReport(final Context context, final Report report) {
    Map<String,String> params = new HashMap<String, String>();
    params.put("our_id", report.getStop().getOurId() + "");
    params.put("type", report.getType().getValue() + "");
    params.put("msg", report.getMessage());

    StringRequest sr = new StringRequest(
            Request.Method.POST,
            POST_REPORT,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    Integer result = Integer.parseInt(response);
                    Log.d(TAG, "REPONSE:" + response + "|");
                    Toast.makeText(context, context.getResources().getStringArray(R.array.post_status)[result], Toast.LENGTH_SHORT).show();
                    update();
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Log.d(TAG, "Error: " + error.getMessage());
                }
            }) {
    };
    sr.setParams(params);
    VolleyApp.getInstance(context).addToRequestQueue(sr);
}
项目:openmap-client-android    文件:Notifications.java   
@Override
public void run() {
    Location l = null;
    if (ContextCompat.checkSelfPermission(getApplicationContext(),
            Manifest.permission.ACCESS_COARSE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
            //l = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    }else{
        ActivityCompat.requestPermissions((Activity)MainActivity.getContext(),
                new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
                10);
    }
    //Create a post request
    final Location finalL = l;
    StringRequest request = new StringRequest(Request.Method.POST,
            "http://api.openpokemap.pw/c", new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            //Find location

            //Handle response
            Log.w("Json", response);
            JsonParser parser = new JsonParser();
            JsonArray pokemons = parser.parse(response).getAsJsonObject()
                    .getAsJsonArray("MapObjects");

            for (int i=0; i<pokemons.size();i++){
                JsonObject o = pokemons.get(i).getAsJsonObject();
                int id = o.get("PokemonId").getAsInt();
                String uuid = o.get("Id").getAsString();
                if(RarePokemons.contains(id)){
                    Log.i("P", "Rare pokemon found!");

                    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);

                    PendingIntent intent = PendingIntent.getActivity(getApplicationContext(), 0,
                            notificationIntent, 0);

                    String name = names.get(id);

                    NotificationCompat.Builder mBuilder =
                            new NotificationCompat.Builder(getApplicationContext())
                                    .setSmallIcon(R.drawable.map)
                                    .setContentTitle("A wild " + name + " is nearby!")
                                    .setContentIntent(intent)
                                    .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 })
                                    .setLights(Color.MAGENTA, 3000, 3000);

                    mNotifyMgr.notify(i, mBuilder.build());
                }
            }
        }

    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("notifications", error.getStackTrace().toString());
            return;
        }
    }){
        @Override
        protected Map<String,String> getParams() {
            Map<String,String> params = new HashMap<String, String>();
            String lat = Double.toString(0);
            String lng = Double.toString(0);
            params.put("lat", lat);
            params.put("lng", lng);
            params.put("p", "true");
            return params;
        }
    };
    queue.add(request);

    //Re run this after 5 minutes
    h.postDelayed(notificationRunnable, 1*60*1000);
}