Android数据库Volley url连接

时间:2017-05-01 02:40:19

标签: android android-volley

如果我将我的IP地址从localhost更改为10.0.2.2,我的应用程序将崩溃。但IP同样适用于模拟器的浏览器。

我的Android代码是:

private void getData() {
    String email = logemail.getText().toString().trim();
    String pass =  logpass.getText().toString().trim();

    if (email.equals("") && pass.equals("")) {
        Toast.makeText(Login.this.getActivity(), "Please enter an email", Toast.LENGTH_LONG).show();
    }
    //Loading = ProgressDialog.show(Login.this.getContext(), "Sign in", "Signinn", false, false);

   // String url = Config.DATA_URL +email+"&Password="+pass;
    String url  = "http://10.0.2.2/getdata.php?Email_ID=rzafridi@hotmail.com&Password=Afridi0000";

    StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
           Loading.dismiss();
            showJSON(response);
        }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(Login.this.getActivity(), error.getMessage().toString(), Toast.LENGTH_LONG).show();

                }
            });
    RequestQueue requestQueue = Volley.newRequestQueue(Login.this.getActivity());
    requestQueue.add(stringRequest);
}
private void showJSON(String response){
    String fname="";
    String phone="";
    try {
        JSONObject jsonObject = new JSONObject(response);
        JSONArray result = jsonObject.getJSONArray(Config.JSON_ARRAY);
        JSONObject collegeData = result.getJSONObject(0);
        fname = collegeData.getString(Config.KEY_NAME);
        phone = collegeData.getString(Config.KEY_PHONE);
    } catch (JSONException e) {
        e.printStackTrace();

0 个答案:

没有答案