Android Open Source - qrscanner Simple Scanner Activity






From Project

Back to project page qrscanner.

License

The source code is released under:

Apache License

If you think the Android project qrscanner listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.qloppy.qrscan.sample;
//from   ww w  .  j ava2 s .c  o  m
import android.content.Context;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Vibrator;
import android.support.v7.app.ActionBarActivity;
import android.widget.Toast;

import com.qloppy.qrscan.QRCodeScannerView;


public class SimpleScannerActivity extends ActionBarActivity implements QRCodeScannerView.ResultHandler {
    private QRCodeScannerView mScannerView;

    @Override
    public void onCreate(Bundle state) {
        super.onCreate(state);
        mScannerView = new QRCodeScannerView(this);
        setContentView(mScannerView);
    }

    @Override
    public void onResume() {
        super.onResume();
        mScannerView.setResultHandler(new QRCodeScannerView.ResultHandler() {

            @Override
            public void handleQrResult(String qrCode) {

            }
        });
        mScannerView.startCamera();
    }

    @Override
    public void onPause() {
        super.onPause();
        mScannerView.stopCamera();
    }

    @Override
    public void handleQrResult(String rawResult) {
        try {
            Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
            r.play();

        } catch (Exception e) {
        }


        // Vibrate for 500 milliseconds
        try {
            Vibrator v = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(500);
        } catch (Exception e) {

        }

        Toast.makeText(this, "Contents = " + rawResult, Toast.LENGTH_SHORT).show();
        mScannerView.startCamera();
    }
}




Java Source Code List

com.qloppy.qrscan.CameraPreview.java
com.qloppy.qrscan.CameraUtils.java
com.qloppy.qrscan.QRCodeScannerView.java
com.qloppy.qrscan.ViewFinderView.java
com.qloppy.qrscan.sample.MainActivity.java
com.qloppy.qrscan.sample.MessageDialogFragment.java
com.qloppy.qrscan.sample.SimpleScannerActivity.java
com.qloppy.qrscan.sample.SimpleScannerFragmentActivity.java