示例#1
0
  private void makeJsonObjectRequest() {
    showpDialog();

    StringRequest sr =
        new StringRequest(
            Request.Method.POST,
            URL_FEED,
            new Response.Listener<String>() {
              @Override
              public void onResponse(String response) {
                // System.out.println("0");
                try {

                  //                    System.out.println(response);
                  //
                  // Toast.makeText(getApplication(),response,Toast.LENGTH_LONG).show();
                  JSONObject obj1 = new JSONObject(response);
                  String status = obj1.getString("status");

                  if (status.equals("success")) {
                    Toast.makeText(
                            getApplication(), "Post successfully added :D", Toast.LENGTH_SHORT)
                        .show();
                    //                        intent = new Intent(Post_Add.this,MainActivity.class);
                    //                        startActivity(intent);
                    finish();

                  } else if (status.equals("error")) {
                    Toast.makeText(
                            getApplication(), "Sorry, there was an error :/", Toast.LENGTH_SHORT)
                        .show();
                  } else {
                    Toast.makeText(getApplication(), "wtf server", Toast.LENGTH_SHORT).show();
                  }

                  //
                  // Toast.makeText(getApplication(),"asdf",Toast.LENGTH_LONG).show();
                  hidepDialog();

                } catch (Exception e) {
                  Toast.makeText(
                          getApplication(),
                          "Something went wrong. Please try again :/",
                          Toast.LENGTH_SHORT)
                      .show();
                  System.out.println(e);
                  hidepDialog();
                  finish();
                }
              }
            },
            new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                // error.printStackTrace();
                System.out.println(error);
                Toast.makeText(getApplication(), "Server is not working :(", LENGTH_SHORT).show();
                hidepDialog();
                finish();
              }
            }) {
          @Override
          protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<String, String>();
            params.put("type", post_type);
            params.put("title", title);
            params.put("content", content);

            return params;
          }

          @Override
          public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();
            params.put("Content-Type", "application/x-www-form-urlencoded");
            return params;
          }
        };

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(sr);
  }
示例#2
0
  private void getautoData() {
    showpDialog();

    StringRequest sr =
        new StringRequest(
            Request.Method.POST,
            URL_FEED,
            new Response.Listener<String>() {
              @Override
              public void onResponse(String response) {
                // System.out.println("0");
                try {

                  //                    System.out.println(response);
                  //
                  // Toast.makeText(getApplication(),response,Toast.LENGTH_LONG).show();
                  JSONObject obj1 = new JSONObject(response);
                  JSONArray tags = new JSONArray(obj1.getString("tags_name"));
                  int len = tags.length();

                  for (int i = 0; i < len; i++) {
                    tagsData[i] = tags.get(i).toString();
                  }

                  //                    System.out.println("1");
                  func();

                  //
                  // Toast.makeText(getApplication(),"asdf",Toast.LENGTH_LONG).show();
                  hidepDialog();

                } catch (Exception e) {
                  Toast.makeText(
                          getApplication(),
                          "Something went wrong. Please try again :/",
                          Toast.LENGTH_SHORT)
                      .show();
                  System.out.println(e);
                  hidepDialog();
                  finish();
                }
              }
            },
            new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                // error.printStackTrace();
                System.out.println(error);
                Toast.makeText(getApplication(), "Server is not working :(", LENGTH_SHORT).show();
                hidepDialog();
                finish();
              }
            }) {
          @Override
          protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<String, String>();
            params.put("user_id", "123");

            return params;
          }

          @Override
          public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();
            params.put("Content-Type", "application/x-www-form-urlencoded");
            return params;
          }
        };

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(sr);
  }