Created
April 25, 2018 02:40
-
-
Save parzibyte/e7b8f8670c2a526ce3d038c29f4fa310 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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