我有一个应用程序,可以扫描二维码。Qr码有一个默认值,如果您扫描它,它将转到一个带有结果的对话框,并将调用具有相同结果的活动
我想要发生的情况是,当qr扫描的结果在对话框中时,如果它的结果与activity相同,它将打开activity,否则它将调用错误的qr。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//We will get scan results here
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
//check for null
if (result != null) {
if (result.getContents() == null) {
// Toast.makeText(this, "Scan Cancelled", Toast.LENGTH_LONG).show();
} else {
//show dialogue with result
showResultDialogue(result.getContents());
}
} else {
// This is important, otherwise the result will not be passed to the fragment
super.onActivityResult(requestCode, resultCode, data);
}
}
//method to construct dialogue with scan results
public void showResultDialogue(final String result) {
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(this);
}
builder.setTitle("Scan Result")
.setMessage(result)
.setPositiveButton("View your Location", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("Scan Result", result);
clipboard.setPrimaryClip(clip);
Intent nxt = new Intent(MainActivity.this, Acad1.class);
startActivity(nxt);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
dialog.dismiss();
}
})
.show();
}
发布于 2018-08-06 11:29:22
不是的。我想要的是,当您扫描与活动同名的二维码时,它将首先打开对话框,然后当您单击视图位置时,它将转到与结果同名的活动。
https://stackoverflow.com/questions/51694702
复制相似问题