Android, How to read QR code in my application?

前端 未结 7 1986
耶瑟儿~
耶瑟儿~ 2020-11-29 16:11

In my application I need to read Qr code. I searched the net and found Zing codes however lots of developers had problem with using it and it seems it is buggy!

If i

7条回答
  •  情话喂你
    2020-11-29 16:42

    Easy QR Code Library

    A simple Android Easy QR Code Library. It is very easy to use, to use this library follow these steps.

    For Gradle:

    Step 1. Add it in your root build.gradle at the end of repositories:

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
    

    Step 2. Add the dependency:

    dependencies {
            compile 'com.github.mrasif:easyqrlibrary:v1.0.0'
    }
    

    For Maven:

    Step 1. Add the JitPack repository to your build file:

    
        
            jitpack.io
            https://jitpack.io
        
    
    

    Step 2. Add the dependency:

    
        com.github.mrasif
        easyqrlibrary
        v1.0.0
    
    

    For SBT:

    Step 1. Add the JitPack repository to your build.sbt file:

    resolvers += "jitpack" at "https://jitpack.io"
    

    Step 2. Add the dependency:

    libraryDependencies += "com.github.mrasif" % "easyqrlibrary" % "v1.0.0"
    

    For Leiningen:

    Step 1. Add it in your project.clj at the end of repositories:

    :repositories [["jitpack" "https://jitpack.io"]]
    

    Step 2. Add the dependency:

    :dependencies [[com.github.mrasif/easyqrlibrary "v1.0.0"]]
    

    Add this in your layout xml file:

    
    
    
        
        

    Add this in your activity java files:

    public class MainActivity extends AppCompatActivity implements View.OnClickListener{
    
        TextView tvData;
        Button btnQRScan;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tvData=findViewById(R.id.tvData);
            btnQRScan=findViewById(R.id.btnQRScan);
    
            btnQRScan.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View view){
            switch (view.getId()){
                case R.id.btnQRScan: {
                    Intent intent=new Intent(MainActivity.this, QRScanner.class);
                    startActivityForResult(intent, EasyQR.QR_SCANNER_REQUEST);
                } break;
            }
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            switch (requestCode){
                case EasyQR.QR_SCANNER_REQUEST: {
                    if (resultCode==RESULT_OK){
                        tvData.setText(data.getStringExtra(EasyQR.DATA));
                    }
                } break;
            }
        }
    }
    

    For customized scanner screen just add these lines when you start the scanner Activity.

    Intent intent=new Intent(MainActivity.this, QRScanner.class);
    intent.putExtra(EasyQR.IS_TOOLBAR_SHOW,true);
    intent.putExtra(EasyQR.TOOLBAR_DRAWABLE_ID,R.drawable.ic_audiotrack_dark);
    intent.putExtra(EasyQR.TOOLBAR_TEXT,"My QR");
    intent.putExtra(EasyQR.TOOLBAR_BACKGROUND_COLOR,"#0588EE");
    intent.putExtra(EasyQR.TOOLBAR_TEXT_COLOR,"#FFFFFF");
    intent.putExtra(EasyQR.BACKGROUND_COLOR,"#000000");
    intent.putExtra(EasyQR.CAMERA_MARGIN_LEFT,50);
    intent.putExtra(EasyQR.CAMERA_MARGIN_TOP,50);
    intent.putExtra(EasyQR.CAMERA_MARGIN_RIGHT,50);
    intent.putExtra(EasyQR.CAMERA_MARGIN_BOTTOM,50);
    startActivityForResult(intent, EasyQR.QR_SCANNER_REQUEST);
    

    You are done. Ref. Link: https://mrasif.github.io/easyqrlibrary

提交回复
热议问题