开发者

QR code game from within android application

开发者 https://www.devze.com 2023-04-03 05:55 出处:网络
I have an android application and I need to integrate QR code within it.On my phone there is installed the Barcode Scanner application.

I have an android application and I need to integrate QR code within it.On my phone there is installed the Barcode Scanner application.

What I want to do is to scan the bar and return the code into my application. Can this be done by using an intent or I need to refer some packages into my android application??

An exa开发者_JAVA技巧ct answer with what should I do will be appreciated.Thank you!

EDIT:Do I need any kind of permissions in the manifest file?


From zxing on Scanning Via Intent:

public Button.OnClickListener mScan = new Button.OnClickListener() {
    public void onClick(View v) {
        Intent intent = new Intent("com.google.zxing.client.android.SCAN");
        intent.setPackage("com.google.zxing.client.android");
        intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
        startActivityForResult(intent, 0);
    }
};

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
            String contents = intent.getStringExtra("SCAN_RESULT");
            String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
            // Handle successful scan
        } else if (resultCode == RESULT_CANCELED) {
            // Handle cancel
        }
    }
}

You can leverage Barcode Scanner with the IntentIntegrator and IntentResult classes also, rather than doing it manually. It makes it very easy to use Barcode Scanner to retrieve bar codes, and even deals with cases where the user doesn't yet have Barcode Scanner installed. I used the IntentIntegrator class in my own app that requires scanning bar codes and retrieving the data.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号