ZXING意图请求代码(标识我的意图) [英] ZXING intent request code (identifying my intent)
问题描述
在我的Android APP中,每当我需要从同一个Activity调用许多不同的ActivitiesForResult时,我都会这样做:
In my Android APP, whenever I need to call many different ActivitiesForResult from the same Activity, I do it like this:
public void firstMethod() {
int requestCode = 1;
Intent intent = new Intent(SomeCode1.class);
startActivityForResult(intent,requestCode);
}
public void secondMethod() {
int requestCode = 2;
Intent intent = new Intent(SomeCode2.class);
startActivityForResult(intent,requestCode);
}
要知道它的意图,我就这样认识他们:
And to know which intent it came from, I recognize them like this:
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case 1: {
// some code
} case 2: {
// some code
}
}
我正在尝试从同一活动中两次调用ZXING条码扫描器,但我不知道如何用它设置请求代码.
I am trying to call the ZXING barcode Scanner twice from the same activity, and I do not know how to set a request code with it.
IntentIntegrator intentintegrator= new IntentIntegrator(this);
IntentIntegrator.initiateScan(ZxingIntent.QR_CODE_TYPES);
有人知道如何做到这一点吗?我需要修改IntentIntegrator代码吗?
Does anybody know how to accomplish this? Do I need to modify the IntentIntegrator code?
推荐答案
我看到2种解决方案.一种可能是创建一个新活动,仅调用IntentIntegrator并将requestCode放入此新活动中.
I see 2 solutions. One would be creating a new activity, just to call the IntentIntegrator and putting the requestCode to this new activity.
第二个选项是修改IntentIntegrator-这就是我所做的.
Second option was to modify the IntentIntegrator - which is what I did.
我删除了最终属性,
// public static final int REQUEST_CODE = 0x0000c0de;
public static int REQUEST_CODE = 0x0000c0de;
添加了设置请求代码的功能:
added the function to set the request code:
public void setRequestCode(int requestCode) {
REQUEST_CODE = requestCode;
}
并且正在像这样调用条形码扫描器:
and am calling the Barcode Scanner like this:
int requestCode = 2;
IntentIntegrator intentintegrator= new IntentIntegrator (this);
intentintegrator.setRequestCode(requestCode);
intentintegrator.initiateScan(ZxingIntent.QR_CODE_TYPES);
我不知道RequestCode 0x0000c0de的用途是什么,为什么它是最终的,但该应用程序似乎可以正常工作.
I do not know what the RequestCode 0x0000c0de is for and why it is final, but the app seems to work.
这篇关于ZXING意图请求代码(标识我的意图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!