Friday, September 30, 2011

[android-developers] barcode scanner not launching

im having a little trouble with my app

i want the barcode scanner to open on the click of a button(scan1),
scan barcode, and return details to a edittext (barcode1).

here is what i have so far......

package com.android.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Scanner extends Activity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.scanner);}

public Button.OnClickListener scan1 = new
Button.OnClickListener() {
public void onClick(View v) {
Intent intent = new
Intent("com.google.zxing.client.android.SCAN");
intent.setPackage("com.google.zxing.client.android");
intent.putExtra("SCAN_MODE", "PRODUCT_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");
// Handle successful scan
EditText editComment =
(EditText)findViewById(R.id.barcode1);
editComment.setText(contents);
} else if (resultCode == RESULT_CANCELED) {
// Handle cancel
}
}
}

}


this is my manifest entry......

<activity android:name=".Scanner" android:label="@string/app_name" >
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>


any help would be great

many thanks

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment