Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.banan.helloworld;
- import android.app.Activity;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.content.Intent;
- import android.view.View;
- import android.widget.Button;
- import android.widget.Toast;
- import com.google.zxing.integration.android.IntentIntegrator;
- import com.google.zxing.integration.android.IntentResult;
- public class MainActivity extends AppCompatActivity {
- private Button scan_button;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- scan_button = (Button) findViewById(R.id.scan_button);
- final Activity activity = this;
- scan_button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- IntentIntegrator integrator = new IntentIntegrator(activity);
- integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES);
- integrator.setPrompt("Scan");
- integrator.setCameraId(0);
- integrator.setBeepEnabled(false);
- integrator.setBarcodeImageEnabled(false);
- integrator.initiateScan();
- }
- });
- }
- @Override
- protected void onActivityResult (int requestCode, int resultCode,Intent intent ){
- IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
- if(result != null) {
- if(result.getContents()==null){
- Toast.makeText(this, "You callcelled the scanning", Toast.LENGTH_LONG).show();
- }
- else{
- Toast.makeText(this, result.getContents(), Toast.LENGTH_LONG).show();
- }
- }
- else{
- super.onActivityResult(requestCode, resultCode, intent);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement