package com.elgin.exemplo;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
import com.elgin.e1.Scanner.*;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void lerCodigo(View view) {
Intent in = Scanner.getScanner(MainActivity.this);
startActivityForResult(in, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if (resultCode == 2) {
String[] result = data.getStringArrayExtra("result");
CharSequence cs;
if (result[0].equals("1")) {
cs = "Codigo: " + result[1] + "\nTipo: " + result[3];
Toast.makeText(MainActivity.this, cs, Toast.LENGTH_LONG).show();
} else {
cs = "Erro # " + result[0] + " na leitura do código.";
Toast.makeText(MainActivity.this, cs, Toast.LENGTH_LONG).show();
}
}
}
}
}