12

I am currently researching to build an alarm clock application in Android. I am utterly and completely new to programming with QR codes. I know nothing about it. But right now, I want to find out the feasibility of creating an application with QR code functionality. (I have two weeks to build this)

My first question is: would I have to handle the camera myself in the code i.e. do I have to fire it up and then close it and then process the QR image?

2nd Q: How would I create the QR code and then when I scan it, how does it know it scanned the right one? I want to print one, place it in the kitchen or bathroom and then when the alarm goes off, I have to scan the code before the alarm turns off.

Johnathan Au
  • 5,061
  • 17
  • 61
  • 120
  • will you help me, i am on same stage, in which you were, i have to make same kind of app, you developed – Sun Jan 09 '14 at 06:58

2 Answers2

16

In Android this requires about 10 minutes:

https://github.com/zxing/zxing/wiki/Scanning-Via-Intent

ffurrer
  • 105
  • 7
Sean Owen
  • 63,876
  • 22
  • 135
  • 169
7

Just donwload the barcode Scanner (QR-Code Scanner) apk file.

http://www.aapktop.com/tag/barcode-scanner-apk http://www.4shared.com/android/2lwrpeHZ/Barcode_Scanner.html http://code.google.com/p/zxing/downloads/detail?name=BarcodeScanner4.31.apk

Install it your device (not on emulator).

now follow these steps.

  1. create a new project
  2. place a button in your XML file.
  3. Make a click event for it and call the (QR-Code Scanner) via intent as

            // Scan Handler
    btnScan.setOnClickListener(new OnClickListener() {
    
        @Override
        public void onClick(View v) {
    
            Intent intent = new Intent(
                    "com.google.zxing.client.android.SCAN");
            intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
            startActivityForResult(intent, 0);
        }
    });
    
  4. Override the onActivityResult Method as

    // ZXing Result Handler
    
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    
    if (requestCode == 0) {
        if (resultCode == RESULT_OK) {
    
    
                contents = intent.getStringExtra("SCAN_RESULT"); // This will contain your scan result
                    String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
    
    
        }
     }
    

Q2

Answer

there are many links out there you can generate the QR-CODE of any type freely. just google it "Online QR CODE generater" http://qrcode.kaywa.com/

Qadir Hussain
  • 8,338
  • 11
  • 82
  • 117
  • Hi, that's very informative thank you. I'm worried about running different tasks simultaneously, in particular, the alarm, the QR task, the camera. Would there be issues with regards to this such as threading or what have you? or does zxing handle these? – Johnathan Au Apr 18 '13 at 12:14
  • Zxing will just decodes your barcode or QR code (in onActivty result ). after that you can do any thing. first i suggest you just try my solution. you have many confusions regarding this. this will clear many things. – Qadir Hussain Apr 18 '13 at 12:17
  • 2
    I would suggest you only use the official download link at code.google.com. You can trust that it's from us (developers). This guidance is good but it can be even easier if you use the `IntentIntegrator` code from the project (https://code.google.com/p/zxing/wiki/ScanningViaIntent). Same idea, just takes care of more small issues for you. Finally -- like any decent app the Barcode Scanner does nothing when not in the foreground so will have no impact on your app when it's not active. – Sean Owen Apr 18 '13 at 14:16