Android, How to read QR code in my application?

前端 未结 7 1982
耶瑟儿~
耶瑟儿~ 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:40

    try {
    
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // "PRODUCT_MODE for bar codes
    
        startActivityForResult(intent, 0);
    
    } catch (Exception e) {
    
        Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
        Intent marketIntent = new Intent(Intent.ACTION_VIEW,marketUri);
        startActivity(marketIntent);
    
    }
    

    and in onActivityResult():

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {           
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0) {
    
            if (resultCode == RESULT_OK) {
                String contents = data.getStringExtra("SCAN_RESULT");
            }
            if(resultCode == RESULT_CANCELED){
                //handle cancel
            }
        }
    }
    

提交回复
热议问题