Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 25, 2018 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/e7b8f8670c2a526ce3d038c29f4fa310 to your computer and use it in GitHub Desktop.
Save parzibyte/e7b8f8670c2a526ce3d038c29f4fa310 to your computer and use it in GitHub Desktop.
package me.parzibyte.ejemplolectorqr;
import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import com.blikoon.qrcodescanner.QrCodeActivity;
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_CODE_QR_SCAN = 101;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, QrCodeActivity.class);
startActivityForResult(i, REQUEST_CODE_QR_SCAN);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != Activity.RESULT_OK) {
Toast.makeText(getApplicationContext(), "No se pudo obtener una respuesta", Toast.LENGTH_SHORT).show();
String resultado = data.getStringExtra("com.blikoon.qrcodescanner.error_decoding_image");
if (resultado != null) {
Toast.makeText(getApplicationContext(), "No se pudo escanear el código QR", Toast.LENGTH_SHORT).show();
}
return;
}
if (requestCode == REQUEST_CODE_QR_SCAN) {
if (data != null) {
String lectura = data.getStringExtra("com.blikoon.qrcodescanner.got_qr_scan_relult");
Toast.makeText(getApplicationContext(), "Leído: " + lectura, Toast.LENGTH_SHORT).show();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment