I'm reading a QR Code as per the code below:
// Botão para abrir câmera e usar o QR Code (Irá abrir a Store para baixar um app nativo)
btnQR = (Button) findViewById(R.id.btnQR);
btnQR.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);
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
Log.i("App","Scan unsuccessful");
}
}
}
private final String TAG = MainActivity.class.getSimpleName();
private CompoundBarcodeView barcodeView;
private BarcodeCallback callback = new BarcodeCallback() {
@Override
public void barcodeResult(BarcodeResult result) {
if (result.getText() != null) {
barcodeView.setStatusText(result.getText());
}
String barcode = "35151022986022000105590000400630036591770797|20151013131745|21.26|";
String[] resp = barcode.split("\|");
String cnpj = resp[0].substring(6, 20); // são 14 dígitos, iniciado da posição 7
String coo = resp[0].substring(30, 35); // supondo que tenham sempre 6 dígitos
String data = resp[1].substring(0, 5); // 6 primeiros dígitos corresponde a data
String total = resp[2];
System.out.println(cnpj);
System.out.println(coo);
System.out.println(data);
System.out.println(total);
try {
Date date = new SimpleDateFormat("yyyyMMdd").parse(data);
} catch (ParseException e) {
e.printStackTrace();
}
String dataFormatada = new SimpleDateFormat("dd/MM/yyyy").format(data);
}
@Override
public void possibleResultPoints(List<ResultPoint> resultPoints) {
}
};
});
I need you to read the QR Code, go back to the application with the fields already filled in.
Fields:
- CNPJ
- Data
- COO
- Total