我使用ZXing Android嵌入式庫讀取QRCode並且onActivityResult
未在QRCode成功掃描後調用,請幫助。ZXing not calling onActivityResult,當掃描QR碼
public class ScanActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_send_money);
Button scanButton = (Button) findViewById(R.id.scan_button);
scanButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
IntentIntegrator integrator = new IntentIntegrator(ScanActivity.this);
integrator.initiateScan();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
System.out.println("*************** Why is this method not called?");
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null) {
if (result.getContents() == null) {
Toast.makeText(this, "Result Not Found", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Result is: ", Toast.LENGTH_LONG).show();
}
} else {
super.onActivityResult(requestCode, resultCode, data);
}
}
}
上面的代碼將正常工作。 onActivityResult方法將在成功掃描條形碼後調用。我已經測試過這種行爲 –