我必须扫描不同的二维码,我想逐个扫描,并通过计数来区分它们,如果数字有12个数字,那么分配它master,如果数字是10,则分配为slaves,这个slaves可以超过1,但master扫描一次。
到目前为止,我已经扫描了一个二维码,但如果我扫描第二个二维码,它会删除那个。
WHat我可以重复扫描并区分它们。
我的代码:
public void ScanButton(View view){
IntentIntegrator intentIntegrator = new IntentIntegrator(this);
intentIntegrator.initiateScan();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data){
IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(intentResult !=null){
//kama imeshindwa kuscan then cancel
if(intentResult.getContents() == null){
Toast toast = Toast.makeText(getApplicationContext(),
"TUnable to Scan, Please Make sure UnaScan QR Code",
Toast.LENGTH_SHORT);
toast.show();
// textView.setText("Unable to Scan, Please Make sure UnaScan QR Code!");
}
else{
textView.setText(intentResult.getContents());
}
}
super.onActivityResult(requestCode, resultCode, data);
}我希望有这样的东西

发布于 2020-06-21 06:34:09
因此,存储二维码内容的一种简单方法是创建一个ArrayList来存储不同的扫描。
ArrayList<String> qrScans = new ArrayList();然后,可能看起来像这样:
public void ScanButton(View view){
IntentIntegrator intentIntegrator = new IntentIntegrator(this);
intentIntegrator.initiateScan();
}
ArrayList<String> qrScans = new ArrayList();
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data){
IntentResult intentResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(intentResult !=null){
//kama imeshindwa kuscan then cancel
if(intentResult.getContents() == null){
Toast toast = Toast.makeText(getApplicationContext(),
"TUnable to Scan, Please Make sure UnaScan QR Code",
Toast.LENGTH_SHORT);
toast.show();
// textView.setText("Unable to Scan, Please Make sure UnaScan QR Code!");
}
else{
qrScans.add(intentResult.getContents());
textView.setText(intentResult.getContents());
}
}
super.onActivityResult(requestCode, resultCode, data);
}这还允许您区分它们,因为它们存储在ArrayList内的不同索引中。因此,您将能够检索非常特定的扫描,然后可以对内容进行操作。
https://stackoverflow.com/questions/62490180
复制相似问题