Reputation: 29
I'm working on a small Android project .. I have the Xzing barcode scanners linked and everything worked. now I need again a scann-button. But when I scan with the second button, it writes me the result in the same field as the first scann-button.can someone help me?
package de.example.addmeter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE); //Fullscreen
setContentView(R.layout.add_strom);
}
public void onClick1 (View view) {
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
String meterid;
meterid = scanResult.getContents();
EditText etmeterid = (EditText) findViewById(R.id.etmeterid);
etmeterid.setText(meterid);
}
}
public void onClick2 (View view) {
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
}
public void onActivityResult1(int requestCode, int resultCode, Intent intent) {
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
String security;
security = scanResult.getContents();
EditText etsecurity = (EditText) findViewById(R.id.etsecurity);
etsecurity.setText(security);
}
}
Upvotes: 1
Views: 384
Reputation: 1755
That onActivityResult1
function is never called. When the Xzing intent returns, you have to manage all the result code in onActivityResult
(that, by the way, should be marked as @Override
).
Normally, what you want should be managed whith different requestCode
, but seems that Xzing intent helper does not allow it.
So, in your case, I would make something like setting a global boolean variable wasCalledFromButton1
, giving it a value in the corresponding onClick
method, an then give the returned value to the correct EditText in onActivityResult
according to this variable.
Upvotes: 1