After the scan to automatically open Activity?

0 like 0 dislike
6 views
In my app there is a scanner "zxing". I need to after the scan is opened "activity_scanner".

Code scanner:
public class ScannerActivity extends AppCompatActivity { static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R. layout.activity_scanner); } /*Start the qr code scanner:*/ public void scanQR(View v) { try { /*Start the transition to com.google.zxing.client.android.SCAN through intent:*/ Intent intent = new Intent(ACTION_SCAN); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); startActivityForResult(intent, 0); } catch (ActivityNotFoundException anfe) { /*It is possible to download from Play Market:*/ showDialog(ScannerActivity.this "Scanner not found", "to Install the scanner from Play Market?", "Yes", "No").show(); } } /*alert dialog to access the app download of scanner:*/ private static AlertDialog showDialog(final Activity act, CharSequence title, CharSequence message,CharSequence buttonYes, CharSequence buttonNo) { AlertDialog.Builder downloadDialog = new AlertDialog.Builder(act); downloadDialog.setTitle(title); downloadDialog.setMessage(message); downloadDialog.setPositiveButton(buttonYes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { /*Link the search request to download the app:*/ Uri uri = Uri.parse("market://search?q=pname:" + "com.google.zxing.client.android"); Intent intent = new Intent(Intent.ACTION_VIEW, uri); try { act.startActivity(intent); } catch (ActivityNotFoundException anfe) { } } }); downloadDialog.setNegativeButton(buttonNo, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { } }); return downloadDialog.show(); } /*Process the result obtained from the application of the scanner:*/ public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == 0) { if (resultCode == RESULT_OK) { /*Get the data after operation of the scanner and display them in Toast the message:*/ String contents = intent.getStringExtra("SCAN_RESULT"); String format = intent.getStringExtra("SCAN_RESULT_FORMAT"); Toast toast = Toast.makeText(this, "Content:" + contents + "Format:" + format, Toast.LENGTH_LONG); toast.show(); startActivity(intent); } } } }


"activity_scanner":
5aebc9f30eeab848245088.png
by | 6 views

1 Answer

0 like 0 dislike
In the method "onActivityResult()" argument "intent" is only to return the scanned barcode.

No "startActivity(intent)" with him to perform.

If you want to leave on the screen the activity, which was to run scanner, it will happen automatically.

But if you want to run another activity - make a new intent:

Intent next = new Intent(this, NextActivity.class);
startActivity(next);
by
110,608 questions
257,186 answers
0 comments
33,905 users