0

I am developing an application that involves QR scanning.I am able to get scanner application working by using Zxing library, which is launched from my application A. I need to store the information of the scanned product in textbox or editbox and later use it for some other purpose .

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent intent = new Intent(MainActivity.this,  
            CaptureActivity.class);  
    // Intent intent = new  
    // Intent("com.google.zxing.client.android.SCAN");  
    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");  
    startActivityForResult(intent, 0);  
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

public void onActivityResult(int requestCode, int resultCode, Intent intent) {  
      if (requestCode == 0) {  
       if (resultCode == 1) {  
        // Handle successful scan  
        String capturedQrValue = intent.getStringExtra("RESULT");  
        // String format =  
        intent.getStringExtra("SCAN_RESULT_FORMAT");  

        Toast.makeText(MainActivity.this,"Scan Result:" + capturedQrValue, Toast.LENGTH_SHORT).show();  
        finish();     
         Intent it=new Intent(MainActivity.this,ThirdActivity.class);
         it.putExtra("Code", capturedQrValue);
         startActivity(it);

Please help me on the same.

meera
  • 199
  • 3
  • 15

2 Answers2

0

then initialize String capturedQrValue globally. and anyway you got the value inside of onActivityResult method. you write one method like this

  public static String getResponce(){
   return capturedQrValue;
  }

call this method from your other activity where you want to show it. hope this helps you

GvSharma
  • 2,632
  • 1
  • 24
  • 30
0

if you want to open your other Activity directly after the scanning you can use this solution:

In your current Activity, create a new Intent:

Intent i = new Intent(getApplicationContext(), NewActivity.class);
i.putExtra("new_variable_name","value");
startActivity(i);

Then in the new Activity, retrieve those values:

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String value = extras.getString("new_variable_name");
    TextField text;//get your textfield by ID or create it in the activity
    text.setText(value);
}

Use this technique to pass variables from one Activity to the other. found here: https://stackoverflow.com/a/7325248/1515052

if you want to open the other Activity later on you maybe want to store the value in a shared preferences file.

http://developer.android.com/guide/topics/data/data-storage.html#pref

Community
  • 1
  • 1
Simulant
  • 19,190
  • 8
  • 63
  • 98