How to start a activity in another activity? Zxing - android

Is it possible to recover the result of the creation of a QR Code ZXing in my own Activity (my xml file)?

Not sure if this is what you are asking for, but you you can scan a barcode using ZXING from one of your activities like this:
try {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);
}
catch (ActivityNotFoundException e) {
}
To do something with the barcode include this:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Toast.makeText(this, contents, Toast.LENGTH_SHORT).show();
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
You need to have the ZXING barcode app installed on your device.

Related

QR Code not showing result using Zxing

I am currently working with qrcode
I added Zxing library and also core.jar.
When I am trying to scan a document not getting any results.
qrscan_button.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
Intent intent = new Intent(
"com.google.zxing.client.android.SCAN");
intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
Toast.makeText(this,
"Scan Result = " + data.getStringExtra("SCAN_RESULT"),
Toast.LENGTH_SHORT).show();
} else if (resultCode == RESULT_CANCELED) {
}
}
}
I added CaptureActivity class in Manifest.
I am using Zxing 2.1

Cannot initiate a call from within an activity

I'm building an app that should allow you to scan a QR code (or barcode) and then calls the nubmer on the barcode/QR code. I'm guessing that you cannot launch a the activity which handles the calls from within another activity because I'm getting the following error:
No Activity found to handle Intent { act=android.intent.action.CALL
dat=tel:xxx=xxx=xxxx }
Here is my code
public void scanNow(View view) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
#SuppressWarnings("deprecation")
public void onActivityResult(int requestCode, int resultCode, Intent intent){
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
try
{
Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(contents));
startActivity(callIntent);
}
catch(Exception e)
{
messageBox("doStuff", e.getMessage());
}
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}

zxing barcode - how to embed the scanner(intent) with other layouts

The code below works for me. However, how could I embed it with other layouts from another activity?
Basically, The screen will be splitted in two parts:
Fist one will contain a header and shared buttons to use in other screens;
Second one will be the Barcode scanner or any other screen.
public Button.OnClickListener mScan = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
};
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
thanks
There isn no way to do this. You are invoking a third-party app and can't control how it looks.

ZXing Library not providing Intent result

I'm using ZXing Library as a library to my Android project. However whenever a barcode is scanned the ZXing Capture activity doesn't provide the result to my activity, it just stands there as if the code had been scanned normally via the application.
My current code is:
discount.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
Intent intent = new Intent(DiscountActivity.this, CaptureActivity.class);
intent.setAction("com.google.xzing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.discount_dialog);
dialog.show();
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
This code is wrong, and more complex than it needs to be. This is all you should be doing: http://code.google.com/p/zxing/wiki/ScanningViaIntent

Does ZXING code scanner also return a picture of the scanned code?

Any ideas if ZXING library for android, besides format and data, can also return an image of the code it just scanned?
Thank!
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
startActivityForResult(intent, 0);
***
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
///NEED TO GET BITMAP OF THE SCANNED CODE
...
} else if (resultCode == RESULT_CANCELED) {
...
}
}
}
No, it does not return this. Look at the source code to see what it constructs as a response.

Categories

Resources