Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am developing a simple project, that QR code scanning is an alternative option for login.

I'm trying to use Zxing I tried almost all of the tutorials on youtube but I can't find my answer.

What I want is when I scan a QR code I can paste the result on my editTextUser and editTextPass.

Thank you so much for your help I don't know where to ask so I hope you can help I really appreciate your help.

What I have tried:

package com.logizard.logizard_go.Activities;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.logizard.logizard_go.Common.LoginManager;
import com.logizard.logizard_go.R;
import com.logizard.logizard_go.models.ResponseDataForCommon;

public class Login extends AppCompatActivity {//implements ZXingScannerView.ResultHandler
    private TextView labelErrorMessage;
    private EditText editTextUser;
    private EditText editTextPass;
    private Button buttonLogin;
    private ImageButton imageButton2;

    static final int GET_SCANNED = 1;

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

        labelErrorMessage = findViewById(R.id.labelErrorMessage);
        editTextUser = findViewById(R.id.editTextUser);
        editTextPass = findViewById(R.id.editTextPass);

        buttonLogin = (Button) findViewById(R.id.buttonLogin);
        buttonLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String userId = editTextUser.getText().toString().trim();
                String password = editTextPass.getText().toString().trim();

                if (userId.isEmpty()){
                    editTextUser.setError("User_ID is empty.");
                    editTextUser.requestFocus();
                    return;
                }

                if (password.isEmpty()){
                    editTextPass.setError("Password is empty.");
                    editTextPass.requestFocus();
                    return;
                }
                LoginTask task = new LoginTask();
                task.execute(userId, password);
            }
        });
        imageButton2 = (ImageButton) findViewById(R.id.imageButton2);

        imageButton2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Login.this, ScanResult.class);
                startActivity(intent);
            }
        });



    }




    private class LoginTask extends AsyncTask<String, String, String> {
        @Override
        protected String doInBackground(String... strings) {
            // The first, the app try to do login with "PROCESS_FLG"'s value is "1"(the meaning is trying as the user is registered).
            LoginManager.login(strings[0], strings[1], "1", (ResponseDataForCommon data) -> {
                // The scene of this app is moved to the main menu.
                Intent intent = new Intent(Login.this, MainMenu.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
            }, (Integer errorCode) -> {
                labelErrorMessage.setText("Couldn't find your Logizard Zero account.");
                System.out.println(errorCode);
            }, (String message) -> {
                labelErrorMessage.setText(message);
            });
            return null;
        }
    }



}
Posted
Comments
Richard MacCutchan 7-Nov-19 4:04am    
You need to explain what the actual problem is.
David Crow 7-Nov-19 9:14am    
I do not see that you are using any ZXing components.

Regarding your "when I scan a QR code I can paste the result on my editTextUser and editTextPass" comment, I see where you are reading values from the editTextUser and editTextPass controls and passing them to LoginManager.login(), but that's it. Shouldn't you be at least using an ZXingScannerView object?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900