SOLVED
i am unable to reach the activityforresult code i dont know what am i doin wrong.
*i have used SCANN instead of SCAN as i have declared it in my manifest
i have referenced zxing lib and also i have the capture activity
my problem is that it calls the scanner properly and also scans it properly but unable to leave that CaptureActivity and come back to activity for result can anyone help please below is my code.
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class QRReader extends Activity {
TextView tvResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.reader);
tvResult = (TextView) findViewById(R.id.scan_result);
Button scanBtn = (Button) findViewById(R.id.btnScan);
// in some trigger function e.g. button press within your code you
// should add:
scanBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
Intent intent = new Intent(
"com.google.zxing.client.android.SCANN");
//tvResult.setText("SCAN_RESULT");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE,PRODUCT_MODE");
startActivityForResult(intent, 0);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Toast.makeText(getApplicationContext(), "ERROR:" + e, 1)
.show();
}
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
System.exit(0);
return true;
}
return super.onKeyDown(keyCode, event);
}
// In the same activity you’ll need the following to retrieve the results:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
tvResult.setText(intent.getStringExtra("SCAN_RESULT"));
Intent i = new Intent(QRReader.this, Fund_Transfer.class);
Bundle extras = new Bundle();
extras.putString("QRcode", tvResult.getText().toString());
i.putExtras(extras);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
} else if (resultCode == RESULT_CANCELED) {
tvResult.setText("Scan cancelled.");
}
}
}
Have you added this lines into your manifest, if yes, then once again verify it.
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateAlwaysHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
call intent as
Intent intent = new Intent(
"com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // QR_CODE,
// DATA_MATRIX,
// UPC_E,
// UPC_A,
// EAN_8,
// EAN_13,
// UPC_EAN_EXTENSION,
// CODE_128,
// CODE_39,
// CODE_93,
// CODABAR,
// ITF,
// RSS14,
// PDF417,
// RSS_EXPANDED
startActivityForResult(intent, REQUEST_CODE);
in your onActivityResult() it should be
resultCode == Activity.RESULT_OK
if this not work, then download library that i am using from here. Add it as your library project. add above code to manifest file. hope it works. It is working for me.