Securing php api to use in android application

前端 未结 7 636
余生分开走
余生分开走 2021-01-31 18:40

I am newbie to android development. I am using android studio for developing an application. Things i have done

  1. Created a DB with two ta
7条回答
  •  日久生厌
    2021-01-31 19:13

    First add the dependencies in build gradle (app)
    implementation 'com.mcxiaoke.volley:library:1.0.16' Then follow the below code:

     final ProgressDialog loading = ProgressDialog.show(getActivity(), "", "Please wait...", false, false);
            StringRequest stringRequest = new StringRequest(Request.Method.POST, ServerLinks.TOTAL_COUNT_URL, new Response.Listener() {
                @Override
                public void onResponse(String response) {
                    loading.dismiss();
                    try {
                        JSONObject jsonObject = new JSONObject(response);
    
                        String status = jsonObject.getString("status");
    
                        if (status.equals("success")) {
                            String data = jsonObject.getString("data");
    
                            JSONObject jsonObject1 = new JSONObject(data);
                            String male = jsonObject1.getString("male");
                            String female = jsonObject1.getString("female");
    
    
                        } else {
                            // no_data_found.setVisibility(View.VISIBLE);
                            Toast.makeText(getActivity(), "No Data Found", Toast.LENGTH_SHORT).show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }//onResponse()
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    loading.dismiss();
                    //Toast.makeText(getActivity(), "Check Your Internet Connection", Toast.LENGTH_SHORT).show();
                }
            });
            int socketTimeout = 30000; // 30 seconds. You can change it
            RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,
                    DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
    
            stringRequest.setRetryPolicy(policy);
            RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
            requestQueue.add(stringRequest);
    

提交回复
热议问题