diff --git a/sample/src/main/java/example/zxing/MainActivity.java b/sample/src/main/java/example/zxing/MainActivity.java index 79f74ec49..b3a0119b1 100644 --- a/sample/src/main/java/example/zxing/MainActivity.java +++ b/sample/src/main/java/example/zxing/MainActivity.java @@ -21,6 +21,8 @@ public class MainActivity extends AppCompatActivity { + public final int CUSTOMIZED_REQUEST_CODE = 0x0000ffff; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -31,6 +33,10 @@ public void scanBarcode(View view) { new IntentIntegrator(this).initiateScan(); } + public void scanBarcodeWithCustomizedRequestCode(View view) { + new IntentIntegrator(this, CUSTOMIZED_REQUEST_CODE).initiateScan(); + } + public void scanBarcodeInverted(View view){ IntentIntegrator integrator = new IntentIntegrator(this); integrator.addExtra(Intents.Scan.INVERTED_SCAN, true); @@ -87,6 +93,18 @@ public void tabs(View view) { @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); + 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"); diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 4fd820f68..4331eee32 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -19,6 +19,12 @@ android:text="@string/scan_barcode" android:onClick="scanBarcode"/> +