Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use the ZXING scan result
    primarykey
    data
    text
    <p>I'm breaking my head over this one. I'm kind of new in android development.</p> <p>I want to use the scan result from ZXING. I integrated ZXING into my android app, the scan works ok. Now I want to use the scan result to update a TextView in the main activity.</p> <p>How can I do that?</p> <p>My code is doing the following for now:</p> <ol> <li>Open Main activity with a button.</li> <li>On clicking the button it activates the scanner.</li> <li>After scanning it goes back to the main activity.</li> <li>The TextView is empty and for some reason it goes back to the original content after moving from landscape to portrait.</li> </ol> <p>After (2) I want to use the scanned result to update the TextView in the main activity (tv in my code).</p> <p>Please help guys, Thanks.</p> <p>My code:</p> <pre><code>public class Main extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button pressToScan = (Button) findViewById(R.id.button1); pressToScan.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent data = new Intent("com.google.zxing.client.android.SCAN"); data.putExtra("SCAN_MODE", "QR_CODE_MODE"); startActivityForResult(data, 0); TextView tv = (TextView) findViewById(R.id.scanResult); tv.setText(data.getStringExtra("SCAN_RESULT")); } }); } public void onActivityResult(int requestCode, int resultCode, Intent data) { String contents = null; super.onActivityResult(requestCode, resultCode, data); if (requestCode == 0) { if (resultCode == RESULT_OK) { contents = data.getStringExtra("SCAN_RESULT"); String format = data.getStringExtra("SCAN_RESULT_FORMAT"); // Handle successful scan } else if (resultCode == RESULT_CANCELED) { // Handle cancel } } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload