Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android应用程序登录和登录问题_Java_Android_Sqlite_Login - Fatal编程技术网

Java Android应用程序登录和登录问题

Java Android应用程序登录和登录问题,java,android,sqlite,login,Java,Android,Sqlite,Login,我正在开发一个android应用程序,其中有一个sigin和注册选项。当新用户第一次进入应用程序时,他需要注册。。当他按下sigin选项时,他被引导到帐户创建页面。在那里他需要输入用户名、密码和手机号码。所有这三个值都存储在sqlite(应用程序内存)中,并创建一个密码并发送到用户提供的手机号码。下一个页面是注册页面,用户的用户名和密码和他收到的密码一起被检查。我做这个过程是为了验证手机号码。因此,我的问题是,一旦用户创建了帐户,返回登录选项并输入用户名和密码。。他正在引导到应用程序的第一页。。

我正在开发一个android应用程序,其中有一个sigin和注册选项。当新用户第一次进入应用程序时,他需要注册。。当他按下sigin选项时,他被引导到帐户创建页面。在那里他需要输入用户名、密码和手机号码。所有这三个值都存储在sqlite(应用程序内存)中,并创建一个密码并发送到用户提供的手机号码。下一个页面是注册页面,用户的用户名和密码和他收到的密码一起被检查。我做这个过程是为了验证手机号码。因此,我的问题是,一旦用户创建了帐户,返回登录选项并输入用户名和密码。。他正在引导到应用程序的第一页。。。因为当帐户创建过程完成时,他的详细信息会保存在应用程序数据库中以供验证。所以用户不需要验证密码。。那么,有没有办法只在注册过程之后才能查看登录按钮呢。。或者类似的事情。。。我在这里发布了siginactivity、signupactivity和register活动。。请检查,如果发现任何错误,请帮助我

注册活动

public class SignUpActivity extends Activity

{

    EditText editTextUserName,editTextPassword,editTextConfirmPassword, editMobileNumber;
    Button btnCreateAccount;



    // Progress Dialog
        private ProgressDialog pDialog;

        JSONParser jsonParser = new JSONParser();




    Random r = new Random();
    int number =r.nextInt(9999 - 1000) + 1000;



    LoginDataBaseAdapter loginDataBaseAdapter;


private static String url_create_data = "http://iascpl.com/app/create_data1.php";

    // JSON Node names
    private static final String TAG_SUCCESS = "success";



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.signup_xm);



        // get Instance  of Database Adapter
                loginDataBaseAdapter=new LoginDataBaseAdapter(this);
                loginDataBaseAdapter=loginDataBaseAdapter.open();

                // Get References of Views


                editTextUserName=(EditText)findViewById(R.id.editTextUserName);
                editTextPassword=(EditText)findViewById(R.id.editTextPassword);
                editTextConfirmPassword=(EditText)findViewById(R.id.editTextConfirmPassword);
                editMobileNumber = (EditText)findViewById(R.id.mobileNumber);




                btnCreateAccount=(Button)findViewById(R.id.buttonCreateAccount);

                btnCreateAccount.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub

                        String name=editTextUserName.getText().toString();
                        String password=editTextPassword.getText().toString();
                        String confirmPassword=editTextConfirmPassword.getText().toString();

                        String phoneNo = editMobileNumber.getText().toString();
                        String sms = Integer.toString(number);


                        //Intent intent = new Intent(SignUpActivity.this, RegisterActivity.class);

                        //intent.putExtra("number", sms + "");
                        //startActivity(intent);



                        //new CreateNewProduct().execute();


                        StringTokenizer st=new StringTokenizer(phoneNo,",");
                        while (st.hasMoreElements())

                        {

                            String tempMobileNumber = (String)st.nextElement();
                            if(tempMobileNumber.length()>0 && sms.trim().length()>0) 
                            {
                                sendSMS(tempMobileNumber, sms);

                            }


                            else 

                            {

                                Toast.makeText(getBaseContext(), 
                                        "Please enter both phone number and message.", 
                                        Toast.LENGTH_SHORT).show();
                            }





                        }








                        // check if any of the fields are vacant
                        if(name.equals("")||password.equals("")||confirmPassword.equals(""))
                        {
                                Toast.makeText(getApplicationContext(), "Field Vaccant", Toast.LENGTH_LONG).show();
                                return;
                        }
                        // check if both password matches
                        if(!password.equals(confirmPassword))
                        {
                            Toast.makeText(getApplicationContext(), "Password does not match", Toast.LENGTH_LONG).show();
                            return;
                        }
                        else
                        {
                            // Save the Data in Database
                           loginDataBaseAdapter.insertEntry(name, password);
                          Toast.makeText(getApplicationContext(), "Passcode is sent to the mobile number you provided. ", Toast.LENGTH_LONG).show();     


                            new CreateNewProduct().execute();

                           // Intent intent = new Intent(SignUpActivity.this, RegisterActivity.class);

                          //  intent.putExtra("number", sms + "");
                           // startActivity(intent);



                        }







                    }
                });

    }









    private void sendSMS(String phoneNumber, String message)
    {
        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";

        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
            new Intent(SENT), 0);

        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
            new Intent(DELIVERED), 0);

      //---when the SMS has been sent---
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS sent", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(getBaseContext(), "Generic failure", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(getBaseContext(), "No service", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getBaseContext(), "Null PDU", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getBaseContext(), "Radio off", 
                                Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        },new IntentFilter(SENT));

        //---when the SMS has been delivered---
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case Activity.RESULT_CANCELED:
                        Toast.makeText(getBaseContext(), "SMS not delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;                        
                }
            }
        }, new IntentFilter(DELIVERED));        

        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);       


    }













    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();

        loginDataBaseAdapter.close();
    }



    /**
     * Background Async Task to Create new product
     * */
    class CreateNewProduct extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(SignUpActivity.this);
            pDialog.setMessage("Creating a new account..");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }

        /**
         * Creating product
         * */
        protected String doInBackground(String... args) {





            String name = editTextUserName.getText().toString();
            String password = editTextPassword.getText().toString();
            String mobile = editMobileNumber.getText().toString();
            String sms = Integer.toString(number);

            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("name", name));
            params.add(new BasicNameValuePair("password", password));
            params.add(new BasicNameValuePair("mobile", mobile));

            // getting JSON Object
            // Note that create product url accepts POST method
            JSONObject json = jsonParser.makeHttpRequest(url_create_data,
                    "POST", params);

            // check log cat fro response
            Log.d("Create Response", json.toString());

            // check for success tag
            try {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // successfully created product




                    Intent i = new Intent(SignUpActivity.this, RegisterActivity.class);

                    i.putExtra("number", sms + "");
                    startActivity(i);

                    //closing this screen
                    //finish();
                } else {
                    // failed to create product
                    return "false";



                }



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

            return null;
        }

        /**
         * After completing background task Dismiss the progress dialog
         * **/
        /*protected void onPostExecute(String file_url) {
            // dismiss the dialog once done
            pDialog.dismiss();
        }*/


        protected void onPostExecute(String result)

        {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
                        if (result == "false")
            Toast.makeText(SignUpActivity.this, "User Name already exists. Please choose another user name ", Toast.LENGTH_LONG).show();
                        pDialog.dismiss();

        }


    }





}
签名活动

public class SignInActivity extends Activity 


{
    /*LoginDataBaseAdapter loginDataBaseAdapter;*/
    Button btnsignin;
    EditText username,userpassword;

    TextView txtName;


    // Progress Dialog
    private ProgressDialog pDialog;

    // JSON parser class
    JSONParser jsonParser = new JSONParser();



    // single product url
    private static String url_get_name = "http://iascpl.com/app/get_name_details.php";


    // JSON Node names
    private static final String TAG_SUCCESS = "success";
    private static final String TAG_PRODUCT = "product";
    private static final String TAG_PASSWORD = "password";


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.signin_xm);


        /*loginDataBaseAdapter=new LoginDataBaseAdapter(this);
        loginDataBaseAdapter=loginDataBaseAdapter.open();*/

        btnsignin = (Button) findViewById ( R.id.button401);
        username=(EditText)findViewById(R.id.editText401);
        userpassword=(EditText)findViewById(R.id.editText402);


        btnsignin.setOnClickListener(new View.OnClickListener() 

        {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub




                new GetProductDetails().execute();

               /* String storedPassword=loginDataBaseAdapter.getSinlgeEntry(userName);*/


                 // check if the Stored password matches with  Password entered by user
                /*if(password.equals(storedPassword)) 
                {
                    Toast.makeText(SignInActivity.this, "Login Successfull", Toast.LENGTH_LONG).show();


                    Intent i = new Intent(SignInActivity.this,HomePageActivity.class);
                    startActivity(i);




                }
                else
                {
                    Toast.makeText(SignInActivity.this, "User Name or Password does not match", Toast.LENGTH_LONG).show();
                }*/



            }
        });
    }



        class GetProductDetails extends AsyncTask<String, String, String> {

            /**
             * Before starting background thread Show Progress Dialog
             * */
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                pDialog = new ProgressDialog(SignInActivity.this);
                pDialog.setMessage("Loading the result... Please wait...");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(true);
                pDialog.show();
            }

            /**
             * Getting product details in background thread
             * */
            protected String doInBackground(String... args) 


            {
                String pid=username.getText().toString();











                            // Building Parameters
                            List<NameValuePair> params = new ArrayList<NameValuePair>();
                            params.add(new BasicNameValuePair("pid", pid));





                            // getting product details by making HTTP request
                            // Note that product details url will use GET request
                            JSONObject json = jsonParser.makeHttpRequest(
                                    url_get_name, "GET", params);



                            // check your log for json response
                            Log.d("Single Product Details", json.toString());


                            // json success tag

                            try {
                            int success = json.getInt(TAG_SUCCESS);

                            if (success == 1) {
                                // successfully received product details
                                JSONArray productObj = json
                                        .getJSONArray(TAG_PRODUCT); // JSON Array

                                // get first product object from JSON Array
                                final JSONObject product = productObj.getJSONObject(0);

                                txtName = (TextView) findViewById(R.id.textView1);

                                // product with this pid found
                                // Edit Text
                                runOnUiThread(new Runnable() {  
                                    @Override
                                    public void run() 
                                    {
                                        // TODO Auto-generated method stub
                                        try {
                                            txtName.setText(product.getString(TAG_PASSWORD));

                                        } catch (JSONException e) {
                                            // TODO Auto-generated catch block
                                            e.printStackTrace();
                                        }
                                    }
                                });


                            }else{
                                // product with pid not found

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




                    return null;
                }


/*
@Override
protected void onDestroy() 
     {
    super.onDestroy();
    // Close The Database
    loginDataBaseAdapter.close();
      }*/


                            /**
                             * After completing background task Dismiss the progress dialog
                             * **/
                            protected void onPostExecute(String result) 
                            {
                                // dismiss the dialog once got all details
                                /*super.onPostExecute(result);
                                if (result == "false")
                                Toast.makeText(SignInActivity.this, "User Name already exists. Please choose another user name ", Toast.LENGTH_LONG).show();*/
                                pDialog.dismiss();
                            }



            }
    }
公共类重要性扩展活动
{
/*LoginDataBaseAdapter LoginDataBaseAdapter*/
按钮btnsignin;
编辑文本用户名、用户密码;
TextView-txtName;
//进度对话框
私人对话;
//JSON解析器类
JSONParser JSONParser=新的JSONParser();
//单一产品url
私有静态字符串url\u get\u name=”http://iascpl.com/app/get_name_details.php";
//JSON节点名称
私有静态最终字符串标记_SUCCESS=“SUCCESS”;
私有静态最终字符串TAG_PRODUCT=“PRODUCT”;
私有静态最终字符串标记\u PASSWORD=“PASSWORD”;
@凌驾
创建时受保护的void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.signin_xm);
/*loginDataBaseAdapter=新的loginDataBaseAdapter(本);
loginDataBaseAdapter=loginDataBaseAdapter.open()*/
btnsignin=(按钮)findViewById(R.id.button401);
用户名=(EditText)findViewById(R.id.editText401);
userpassword=(EditText)findViewById(R.id.editText402);
setOnClickListener(新视图.OnClickListener()
{
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
新建GetProductDetails().execute();
/*String storedPassword=loginDataBaseAdapter.getSinlgeEntry(用户名)*/
//检查存储的密码是否与用户输入的密码匹配
/*if(password.equals(storedPassword))
{
Toast.makeText(SignInActivity.this,“登录成功”,Toast.LENGTH_LONG.show();
意图i=新意图(SignInActivity.this,HomePageActivity.class);
星触觉(i);
}
其他的
{
Toast.makeText(SignInActivity.this,“用户名或密码不匹配”,Toast.LENGTH_LONG.show();
}*/
}
});
}
类GetProductDetails扩展了AsyncTask{
/**
*在启动后台线程显示进度对话框之前
* */
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=新建进度对话框(signianctivity.this);
setMessage(“正在加载结果…请稍候…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(真);
pDialog.show();
}
/**
*在后台线程中获取产品详细信息
* */
受保护的字符串doInBackground(字符串…args)
{
字符串pid=username.getText().toString();
//建筑参数
List params=new ArrayList();
参数添加(新的BasicNameValuePair(“pid”,pid));
//通过发出HTTP请求获取产品详细信息
//请注意,产品详细信息url将使用GET请求
JSONObject json=jsonParser.makeHttpRequest(
url_get_name,“get”,params);
//检查日志中的json响应
Log.d(“单一产品详细信息”,json.toString());
//json成功标记
试一试{
int success=json.getInt(TAG_success);
如果(成功==1){
//已成功接收产品详细信息
JSONArray productObj=json
.getJSONArray(TAG_PRODUCT);//JSON数组
//从JSON数组中获取第一个产品对象
最终JSONObject产品=productObj.getJSONObject(0);
txtName=(TextView)findViewById(R.id.textView1);
//找到具有此pid的产品
//编辑文本
runOnUiThread(新的Runnable(){
@凌驾
公开募捐
{
//TODO自动生成的方法存根
试一试{
setText(product.getString(TAG_PASSWORD));
}捕获(JSONException e){
public class SignInActivity extends Activity 


{
    /*LoginDataBaseAdapter loginDataBaseAdapter;*/
    Button btnsignin;
    EditText username,userpassword;

    TextView txtName;


    // Progress Dialog
    private ProgressDialog pDialog;

    // JSON parser class
    JSONParser jsonParser = new JSONParser();



    // single product url
    private static String url_get_name = "http://iascpl.com/app/get_name_details.php";


    // JSON Node names
    private static final String TAG_SUCCESS = "success";
    private static final String TAG_PRODUCT = "product";
    private static final String TAG_PASSWORD = "password";


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.signin_xm);


        /*loginDataBaseAdapter=new LoginDataBaseAdapter(this);
        loginDataBaseAdapter=loginDataBaseAdapter.open();*/

        btnsignin = (Button) findViewById ( R.id.button401);
        username=(EditText)findViewById(R.id.editText401);
        userpassword=(EditText)findViewById(R.id.editText402);


        btnsignin.setOnClickListener(new View.OnClickListener() 

        {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub




                new GetProductDetails().execute();

               /* String storedPassword=loginDataBaseAdapter.getSinlgeEntry(userName);*/


                 // check if the Stored password matches with  Password entered by user
                /*if(password.equals(storedPassword)) 
                {
                    Toast.makeText(SignInActivity.this, "Login Successfull", Toast.LENGTH_LONG).show();


                    Intent i = new Intent(SignInActivity.this,HomePageActivity.class);
                    startActivity(i);




                }
                else
                {
                    Toast.makeText(SignInActivity.this, "User Name or Password does not match", Toast.LENGTH_LONG).show();
                }*/



            }
        });
    }



        class GetProductDetails extends AsyncTask<String, String, String> {

            /**
             * Before starting background thread Show Progress Dialog
             * */
            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                pDialog = new ProgressDialog(SignInActivity.this);
                pDialog.setMessage("Loading the result... Please wait...");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(true);
                pDialog.show();
            }

            /**
             * Getting product details in background thread
             * */
            protected String doInBackground(String... args) 


            {
                String pid=username.getText().toString();











                            // Building Parameters
                            List<NameValuePair> params = new ArrayList<NameValuePair>();
                            params.add(new BasicNameValuePair("pid", pid));





                            // getting product details by making HTTP request
                            // Note that product details url will use GET request
                            JSONObject json = jsonParser.makeHttpRequest(
                                    url_get_name, "GET", params);



                            // check your log for json response
                            Log.d("Single Product Details", json.toString());


                            // json success tag

                            try {
                            int success = json.getInt(TAG_SUCCESS);

                            if (success == 1) {
                                // successfully received product details
                                JSONArray productObj = json
                                        .getJSONArray(TAG_PRODUCT); // JSON Array

                                // get first product object from JSON Array
                                final JSONObject product = productObj.getJSONObject(0);

                                txtName = (TextView) findViewById(R.id.textView1);

                                // product with this pid found
                                // Edit Text
                                runOnUiThread(new Runnable() {  
                                    @Override
                                    public void run() 
                                    {
                                        // TODO Auto-generated method stub
                                        try {
                                            txtName.setText(product.getString(TAG_PASSWORD));

                                        } catch (JSONException e) {
                                            // TODO Auto-generated catch block
                                            e.printStackTrace();
                                        }
                                    }
                                });


                            }else{
                                // product with pid not found

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




                    return null;
                }


/*
@Override
protected void onDestroy() 
     {
    super.onDestroy();
    // Close The Database
    loginDataBaseAdapter.close();
      }*/


                            /**
                             * After completing background task Dismiss the progress dialog
                             * **/
                            protected void onPostExecute(String result) 
                            {
                                // dismiss the dialog once got all details
                                /*super.onPostExecute(result);
                                if (result == "false")
                                Toast.makeText(SignInActivity.this, "User Name already exists. Please choose another user name ", Toast.LENGTH_LONG).show();*/
                                pDialog.dismiss();
                            }



            }
    }
 SharedPreferences set = getSharedPreferences(PREFS_NAME, 0); 
                        SharedPreferences.Editor ed = set.edit(); 
                        ed.putString("l", "l"); 
                        ed.commit();
btn3.setVisibility(View.INVISIBLE);
                 btn4.setVisibility(View.INVISIBLE);