Android Volley帖子请求无法点击?

时间:2017-02-24 20:09:55

标签: android json post parameters android-volley

我正在创建一个应用程序,我可以在其中生成报告,并且在按钮单击时没有任何反应,即使响应没有到来,吐司也没有显示。这个凌空的帖子我以前使用它并且它是正确的,我应该写的另一件事是我必须发送令牌进行授权。 这是我的代码:



      //this is button click
      btnUpload.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                volley_send();


                }

        });
        
       //-----------------------------------------------------
       
       //this is volley post
       
 private void volley_send(){


        StringRequest stringRequest = new StringRequest(Request.Method.POST, "my_url",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        
                        // save_on_sharedPreference("email",email);
                      


                        if(!response.isEmpty()){
                            try {

                                JSONObject jsonObject = new JSONObject(response);
                                error = jsonObject.getBoolean("error");
                                String message = jsonObject.getString("message");

                                if(!error){

                                    //String token = jsonObject.getString("token");
                                    //JSONObject data = jsonObject.getJSONObject("data");



                                   

                                    Toast.makeText(getApplicationContext(),message,Toast.LENGTH_SHORT).show();

                                    Intent intent = new Intent(getApplicationContext(), Raport_Cat_NoPhoto.class);
                                    startActivity(intent);

                                }
                                else{
                                    Toast.makeText(getApplicationContext(),message,Toast.LENGTH_SHORT).show();
                                }



                                // JSONArray feedArray = response.getJSONArray("data");
                            } catch (JSONException e) {
                                e.printStackTrace();
                                System.out.println("JSONException :"+e.toString() );

                            }
                        }

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                        if (error instanceof TimeoutError || error instanceof NoConnectionError) {
                            Toast.makeText(getApplicationContext(),getString(R.string.err_connection),Toast.LENGTH_SHORT).show();
                        } else if (error instanceof AuthFailureError) {
                            //TODO
                            //Toast.makeText(getApplicationContext(),"2",Toast.LENGTH_SHORT).show();
                            Toast.makeText(getApplicationContext(),getString(R.string.err_authentication),Toast.LENGTH_SHORT).show();
                        } else if (error instanceof ServerError) {
                            //TODO
                            //Toast.makeText(getApplicationContext(),"3",Toast.LENGTH_SHORT).show();
                            Toast.makeText(getApplicationContext(),getString(R.string.err_system),Toast.LENGTH_SHORT).show();
                        } else if (error instanceof NetworkError) {
                            //TODO
                            //Toast.makeText(getApplicationContext(),"4",Toast.LENGTH_SHORT).show();
                            Toast.makeText(getApplicationContext(),getString(R.string.err_network),Toast.LENGTH_SHORT).show();
                        } else if (error instanceof ParseError) {
                            //TODO
                            //Toast.makeText(getApplicationContext(),"5",Toast.LENGTH_SHORT).show();
                            Toast.makeText(getApplicationContext(),getString(R.string.err_processing),Toast.LENGTH_SHORT).show();
                        }

                    }
                }){


            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("Authorization","Bearer "+ApiKey);
                return headers;
            }

            @Override
            protected Map<String,String> getParams(){
                Map<String,String> params = new HashMap<String, String>();
                params.put("category","cat_ankese");
                params.put("description",description.getText().toString());
                params.put("city",Qyteti);
                params.put("fshati",fshati.getText().toString());
                params.put("address",address.getText().toString());
                params.put("additional_information1",personidyshuar.getText().toString());
                params.put("name",emer.getText().toString());
                params.put("surname",mbiemer.getText().toString());
                params.put("telephone",telefon.getText().toString());
                params.put("email",email.getText().toString());
                params.put("info_latt",my_latitude);
                params.put("info_long",my_longitude);
                params.put("file[]",image123);
                return params;
            }

        };

        RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
        requestQueue.add(stringRequest);
    }
&#13;
&#13;
&#13;

我不知道这是错的......

1 个答案:

答案 0 :(得分:0)

问题就像授权标题一样,因为它只需要一个参数。谢谢大家的回复!