summaryrefslogtreecommitdiff
path: root/sample/src/main/java/example/zxing/MainActivity.java
diff options
context:
space:
mode:
authorRalf Kistner <ralf@journeyapps.com>2018-03-04 14:05:59 +0300
committerRalf Kistner <ralf@journeyapps.com>2018-03-04 14:05:59 +0300
commit2f022c0a70b0faea61d8b72100d536426cad25c8 (patch)
tree388adf592368f478074236c0bde61586f889a7fa /sample/src/main/java/example/zxing/MainActivity.java
parent3fd9354cd778f0576297ca5586bfe9dee7ee2bb4 (diff)
downloadzxing-android-embedded-2f022c0a70b0faea61d8b72100d536426cad25c8.tar.xz
Make requestCode non-static.
Diffstat (limited to 'sample/src/main/java/example/zxing/MainActivity.java')
-rw-r--r--sample/src/main/java/example/zxing/MainActivity.java30
1 files changed, 14 insertions, 16 deletions
diff --git a/sample/src/main/java/example/zxing/MainActivity.java b/sample/src/main/java/example/zxing/MainActivity.java
index b3a0119b..f8af3a54 100644
--- a/sample/src/main/java/example/zxing/MainActivity.java
+++ b/sample/src/main/java/example/zxing/MainActivity.java
@@ -34,7 +34,7 @@ public class MainActivity extends AppCompatActivity {
}
public void scanBarcodeWithCustomizedRequestCode(View view) {
- new IntentIntegrator(this, CUSTOMIZED_REQUEST_CODE).initiateScan();
+ new IntentIntegrator(this).setRequestCode(CUSTOMIZED_REQUEST_CODE).initiateScan();
}
public void scanBarcodeInverted(View view){
@@ -92,30 +92,28 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
+ if (requestCode != CUSTOMIZED_REQUEST_CODE && requestCode != IntentIntegrator.REQUEST_CODE) {
+ // This is important, otherwise the result will not be passed to the fragment
+ super.onActivityResult(requestCode, resultCode, data);
+ return;
+ }
switch (requestCode) {
case CUSTOMIZED_REQUEST_CODE: {
Toast.makeText(this, "REQUEST_CODE = " + requestCode, Toast.LENGTH_LONG).show();
break;
}
- case IntentIntegrator.REQUEST_CODE: {
- Toast.makeText(this, "IntentIntegrator default REQUEST_CODE = " + requestCode, Toast.LENGTH_LONG).show();
- break;
- }
default:
break;
}
- if(result != null) {
- if(result.getContents() == null) {
- Log.d("MainActivity", "Cancelled scan");
- Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
- } else {
- Log.d("MainActivity", "Scanned");
- Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
- }
+
+ IntentResult result = IntentIntegrator.parseActivityResult(resultCode, data);
+
+ if(result.getContents() == null) {
+ Log.d("MainActivity", "Cancelled scan");
+ Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
- // This is important, otherwise the result will not be passed to the fragment
- super.onActivityResult(requestCode, resultCode, data);
+ Log.d("MainActivity", "Scanned");
+ Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show();
}
}