首页 > 解决方案 > 如何使用android在数据库中登录用户信息

问题描述

private void LogInFunction() { Map<String,String> 参数 =new HashMap<String,String>();

    RequestQueue rq = Volley.newRequestQueue(this);

    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
            (Request.Method.GET, "http://10.0.2.2/CPanelNewsApp/Usercheck.php?email="+edemail.getText().toString()+"&&"+"password="+edpass.getText().toString(),
                    null,new Response.Listener<JSONObject>() {

                @Override
                public void onResponse(JSONObject response) {

                    try {
                        JSONArray jsonArray = response.getJSONArray("dishs");

// Toast.makeText(getApplicationContext(),"数据已发送到服务器:) ",Toast.LENGTH_SHORT).show();

                        String stat =    jsonArray.getJSONObject(0).get("Stat").toString();

// Toast.makeText(getApplicationContext(),"欢迎用户 :) stat = "+stat,Toast.LENGTH_SHORT).show();

                        if(stat.matches("1")){

                            //receive user data from database;;;
                            userId = (jsonArray.getJSONObject(0).get("id").toString());
                            userName = (jsonArray.getJSONObject(0).get("name").toString());
                            userPhone = (jsonArray.getJSONObject(0).get("email").toString());
                            userEmail = (jsonArray.getJSONObject(0).get("phone").toString());
                            userPassword = (jsonArray.getJSONObject(0).get("password").toString());

// Toast.makeText(getApplicationContext(),"我们找到数据",Toast.LENGTH_SHORT).show();

                            //send user data to EditData.java;;;
                            Intent intent = new Intent(MainActivity.this,ViewCats.class);
                            intent.putExtra("userId",userId);
                            intent.putExtra("userName",userName);
                            intent.putExtra("userPhone",userPhone);
                            intent.putExtra("userEmail",userEmail);
                            intent.putExtra("userPassword",userPassword);
                            startActivity(intent);

                        }else{

                            Toast.makeText(getApplicationContext(),"No User !!!  ",Toast.LENGTH_SHORT).show();

                        }

                    } catch (JSONException e) {
                        e.printStackTrace();

                    }


                }

// by prog hazem ahmad <<< www.beprogrammer.org >>> ...

            }, new Response.ErrorListener() {

                @Override
                public void onErrorResponse(VolleyError error) {
                    // TODO: Handle error
                    Toast.makeText(getApplicationContext(),"Error Response 102",Toast.LENGTH_SHORT).show();

                }
            }

标签: javaandroid

解决方案


推荐阅读