How to Retrieve product id from bar code? - android

I have used the same way of Zxing Intent to open scanner from my application. But my application just opens scanner and does nothing. Also, I am getting some FileNotfoundException.
Do I have to add any permission in manifest?
This is my class where I use Intent:
public class BarCodes extends Activity {
/** Called when the activity is first created. */
#Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button ok;
ok=(Button) findViewById(R.id.b1);
ok.setOnClickListener(new View.OnClickListener() {
#Override public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE","QR_CODE_MODE");
startActivityForResult(intent, 0);
}
});
System.out.println("SSSSSSSSSSSSS");
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
System.out.println("contentsssssssssssssssssssssss" + contents);
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}
}
Also LogCat is here:
java.lang.RunTimeException:Unable to instantiate activity componentInfo{com.pkg.BarCode...}
caused by : java.lang.classNotFoundException:com.pkg.Scan in loader dalvik.System Loader…
What might be the problem??

This question is answered in more detail here and here. As to why you are getting the FileNotFoundException you'd have to provide more detail, such as the code for which you are invoking the Zxing intent as well as the logcat stack trace.

Your error is nothing to do with the project. Android is saying it is unable to find your class, com.pkg.Scan. You'll have to fix your project setup.
However I'd further suggest that you not try to write your own code, but use the code provided by the project to integrate via Intent.

Steps:
Install Apache Ant (http://www.youtube.com/watch?v=XJmndRfb1TU , this video will help you to do that) and also refer http://ant.apache.org/ for more info and download ant
Download the ZXing source from ZXing homepage and extract it (For More info :http://code.google.com/p/zxing/source/browse/trunk/android/)
With the use of Windows Commandline (Run->CMD) navigate to the extracted directory
Type 'ant -f core/build.xml' or 'ant -f android/build.xml'
Enter Eclipse -> new Android Project
Right-click project folder -> Properties -> Java Build Path -> Library -> Add External JARs
If the Barcode Scanner is installed on your Android device, you can have it scan for you and return the result, just by sending it an Intent. For example, you can hook up a button to scan a QR code in this way
It will have the product code Stored in the String value 'contents'
Have fun with BarCode by implementing it in your own way :-)

Related

Braintree Android SDK Drop-in UI not displayed

I am trying to display the Drop-in UI in my app upon clicking a specific button. I have used the guide from Braintree site but for some reason nothing is happening.
Code below:
OnClick function:
public void onClick(View v){
switch (v.getId()){
case R.id.showUI_button:
onBraintreeSubmit(v);
break;
}
}
Drop-in functions:
public void onBraintreeSubmit(View v) {
PaymentRequest paymentRequest = new PaymentRequest()
.clientToken(token)
.amount("$10.00")
.primaryDescription("Awesome payment")
.secondaryDescription("Using the Client SDK")
.submitButtonText("Pay");
startActivityForResult(paymentRequest.getIntent(this), REQUEST_CODE);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE) {
if (resultCode == BraintreePaymentActivity.RESULT_OK) {
PaymentMethodNonce paymentMethodNonce = data.getParcelableExtra(
BraintreePaymentActivity.EXTRA_PAYMENT_METHOD_NONCE
);
String nonce = paymentMethodNonce.getNonce();
// Send the nonce to your server.
}
}
}
I have checked that the token is returned from the server.
I have also tried by setting the onClick via the xml code of the button and removing the onClick from the java file but the result is the same, no UI shown.
The log has only two lines
performCreate Call Injection Manager
Timeline: Activity_idle id:android.os.BinderProxy#etc
Any ideas? If more info is needed to understand better let me know
Actually I found this there is a "BraintreeFragment" set up part. Braintree documentation needs to be more clear on this I think.
https://developers.braintreepayments.com/guides/client-sdk/setup/android/v2
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
mBraintreeFragment = BraintreeFragment.newInstance(this, mAuthorization);
// mBraintreeFragment is ready to use!
} catch (InvalidArgumentException e) {
// There was an issue with your authorization string.
}
}
The above code should work along with the previous code posted. mAuthorization is the token and needs to be valid to show the payment screen (so the variable "token" in the previous code posted which in my code I just have as private but visible from the whole activity).
Try with the test token that they have on their page and if this works then the main setup is ok.
https://developers.braintreepayments.com/start/hello-client/android/v2
For setting up tokens on your server, they have further documentation so that those test tokens work on the sandbox.

Authenticate using Box Android SDK v2

I want to authenticate using the Box SDK.
I got the Box Java SDK V2 and the Box Android SDK V2.
And I'm using the basic authentication code from the Box Android SDK
Intent intent = OAuthActivity.createOAuthActivityIntent(this, clientId,
clientSecret);
startActivityForResult(intent);
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_CANCELED) {
// Get the error message for why authentication failed.
String failMessage = data.getStringExtra(OAuthActivity.ERROR_MESSAGE);
// Implement your own logic to handle the error.
handleFail(failMessage);
} else {
// You will get an authenticated BoxClient object back upon success.
BoxClient client =
data.getParcelableExtra(OAuthActivity.BOX_CLIENT);
youOwnMethod(client);
}
}
but I'm getting this error:
The method createOAuthActivityIntent(Context, String, String) from the type OAuthActivity refers to the missing type Intent
It's probably something stupid I'm doing wrong, but can someone tell me what?
It seems Intent class cannot be found? This is an android class. Are you working on an android project or a regular java project? Do you see any compile error?

Android Zxing (barcode library). How to change the after scan intent

I am developing an Android application, I need to embed the Zxing scanner. The application should allow the user to scan a QR Code and then store the QR code ID of the product and parse it from an XML file. As yet, I have used the simple code:
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.setPackage(getPackageName());
intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
What this code does is, scans the product and bring me back to the previous screen of my app. I haven't included the entire library from Zxing as I wanted the Barcode scanner to handle it, but it seems I have to do more than I already have done.
You need to make an onActivityResult method that will get the callback once barcode scanner is done. Inside there you will handle the code string and do whatever you like with it.
/*Here is where we come back after the Barcode Scanner is done*/
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
// contents contains whatever the code was
String contents = intent.getStringExtra("SCAN_RESULT");
// Format contains the type of code i.e. UPC, EAN, QRCode etc...
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
Log.i("TAG",format + "\t" + contents);
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel. If the user presses 'back' before a code is scanned.
Log.i("TAG","Canceled");
}
}
}
This example just logs the results, you'll need to expand upon it to do whatever you want with the info you get back from the scanner.
Better still, use the IntentIntegrator class supplied with the project. It wraps up all the details listed here and its documentation already tells you exactly how to integrate it into your app. It deals with things for you like getting the app installed if not already.

How does the Android scanner work?

Does any one know how the Android scanner works? Does it work like a barcode scanner? And can it scan anything you program it to? If anyone knows where I could learn more about it, please let me know.
This is what i have done
0.Installed the barcode scanner app.
1.go to the link ...(http://code.google.com/p/zxing/downloads/list)
2.download the latest zip file
3.converted the core folder to jar file and added to my proj as external libraries.(It contains all the necessary code to decode the barcodes).
An do something like this
public final Button.OnClickListener openbrowser = new Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(INTENT_SCAN);
intent.putExtra(SCAN_MODE, QR_CODE_MODE);
startActivityForResult(intent, REQCODE_SCAN);
}
};
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
t1 = (TextView) findViewById(R.id.content);
if (requestCode == REQCODE_SCAN) {
t1.setText(data.getStringExtra(SCAN_RESULT));
s = data.getStringExtra(SCAN_RESULT);
try {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(s));
startActivity(browserIntent);
} catch (Exception e) {
e.printStackTrace();
}
}
}
5.This was just to decode the url in barcode. to encode your url into qr code .use qr code generators online like this (http://qrcode.kaywa.com/)
6.the above example was to decode url and open it in browser automatically by passing intent to barcodescanner app previously installed.
If you want to use your own barcode scanner libraries, it takes lot of your time. If your thinking in those lines better explore the ZXING code.
I would personally recommend to use those libraries and write a simple by passing intents. There lot of ways to decode barcodes look at this class
http://code.google.com/p/zxing/source/browse/trunk/androidtest/src/com/google/zxing/client/androidtest/ZXingTestActivity.java
hope all this helps.
zebra crossing qr code scanning libraries....
http://code.google.com/p/zxing/
Scanner example
http://malsandroid.blogspot.com/2010/07/using-barcode-scanner.html

Basic ZXING library application

I am trying to produce
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
}
}
}
Using the libraries therefore not needing to install the software, I have had a look at the application that comes with it, and added CaptureActivity.java to my project to see if I can locate the core scanning loop but it kept just requiring more and more files (ended up with about 28 in total) and after I had no errors it still didn't work.
I am not looking into doing anything fancy, just on a button click open the capture layout, scan a code, return the code.
There are a few examples on how to decode local files but not the actual scanning side of it to detect a actual barcode.
So, what I help with is embedding the scanning code
Thanks
I think you're mixing up two things. The code you have shows you are trying to integrate via Intent, in which case you do not need any project code in your application at all.
The source in android/ is a complete stand-alone app (Barcode Scanner) and it is not written for you to copy (although the Apache License permits it). What you are doing is not supported, recommended, or encouraged -- integrating via Intent is much easier.
Write your own app, perhaps looking to the Android source code for inspiration, and that uses the core/ library for scanning. The core scanning happens in DecodeThread.

Categories

Resources