0
I’m trying to use the camera phone as a barcode reader.
I can retrieve the barcode, and see the result inside the "onActivityResult", however, I need to take the result I got, to my main function, and I’m not getting.
Follow the code below.
Main function:
public void clickProducts(){
listProdutos.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
showCamera();
ShowCamera function:
private void showCamera() {
try {
//start the scanning activity from the com.google.zxing.client.android.SCAN intent
Intent intent = new Intent(ACTION_SCAN);
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);
} catch (ActivityNotFoundException anfe) {
//on catch, show the download dialog
showDialog(ProductsListToThatSchoolAndUser.this, "Nenhuma câmera habilitada.", "Download a scanner code activity?", "Sim", "Não").show();
}
}
onActivityResult:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
//get the extras that are returned from the intent
String contents = intent.getStringExtra("SCAN_RESULT");
Toast.makeText(ProductsListToThatSchoolAndUser.this, contents, Toast.LENGTH_LONG).show();
}
}
}
I would like to use the result of "Contents", within my function "clickProducts()", but I’m not getting it.
got it. I tried to set the content in an Edittext that I have inside this page and it didn’t work. I’m starting now android programming, many things are still new to me.
– Bruno Andrade
private void handleScanResult(String Contents){ //Do here what you want with
contents

 LayoutInflater inflater = getLayoutInflater();
 final View dialogView = inflater.inflate(R.layout.alert_dialog_product ,null);
 final EditText cbarrasLeitor = (EditText) dialogView.findViewById(R.id.cbarrascheck);

 cbarrasLeitor.setText(Contents); }– Bruno Andrade
Bruno, this is another problem and should be addressed in another question. See how the site works on tour and in How to ask.
– ramaral