0

My requirement is:

  1. Browse the image from the gallery
  2. Identify the barcodes and their type on the image which was picked from the gallery.

As of now, I Tried the following code to get the image from gallery and it worked fine, But after getting the image, how exactly I should proceed?

Please help me out. Thanks in advance, Jai

package com.example.testapp;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class BrowsePictureActivity extends Activity {

// this is the action code we use in our intent, 
// this way we know we're looking at the response from our own action
private static final int SELECT_PICTURE = 1;

private String selectedImagePath;

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

    ((Button) findViewById(R.id.Button01))
            .setOnClickListener(new OnClickListener() {

                public void onClick(View arg0) {

                    // in onCreate or any event where your want the user to
                    // select a file
                    Intent intent = new Intent();
                    intent.setType("image/*");
                    intent.setAction(Intent.ACTION_GET_CONTENT);
                    startActivityForResult(Intent.createChooser(intent,
                            "Select Picture"), SELECT_PICTURE);
                }
            });
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {
            Uri selectedImageUri = data.getData();
            selectedImagePath = getPath(selectedImageUri);
        }
    }
}

/**
 * helper to retrieve the path of an image URI
 */
public String getPath(Uri uri) {
        // just some safety built in 
        if( uri == null ) {
            // TODO perform some logging or show user feedback
            return null;
        }
        // try to retrieve the image from the media store first
        // this will only work for images selected from gallery
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        if( cursor != null ){
            int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        }
        // this is our fallback here
        return uri.getPath();`enter code here`
}

}
Asfab
  • 402
  • 6
  • 11
  • Pass the image to a barcode utility, if installed on your phone for processing. This will be of huge help: http://stackoverflow.com/questions/4854442/embed-zxing-library-without-using-barcode-scanner-app – Skynet Dec 30 '13 at 09:07
  • Oh,thanks a lot Astral..that article is really so much helpful. – user2978725 Dec 30 '13 at 09:26
  • You are welcome :) Happy coding! – Skynet Dec 30 '13 at 09:26
  • hey Astral, the article you provided will scan all the barcodes present in the image? am very new to android, soPlease answer me Astral – user2978725 Dec 30 '13 at 09:34
  • It truly depends on your implementation. You can inbuilt that in your app or you can send the image over to the bar-code scanner app, if installed on the phone. Else prompt the user to install it. However in your scenario I think embedding the desired behavior would be better. – Skynet Dec 30 '13 at 09:36
  • thanks astral, I really owe you a lot..I supposed to submit this app within a week or else i might loose the job too... – user2978725 Dec 30 '13 at 09:44
  • Don't worry mate, coding is fun. Just don't lose the focus! – Skynet Dec 30 '13 at 10:06
  • Check this out: https://github.com/embarkmobile/zxing-android-minimal – Skynet Dec 30 '13 at 10:07
  • Hi Astral, can you pls help me out in developing this app.. – user2978725 Dec 31 '13 at 05:35
  • I stuck in identifying and decoding the barcodes on the given image,pls help me out Astral, ts too crucial for me. – user2978725 Dec 31 '13 at 05:44
  • I wish I could, I work too and my time is limited. However you can mail me your project at j.sakib03@gmail.com and Ill have a look on the weekend. – Skynet Dec 31 '13 at 05:49
  • oh, thanks a lotttttttttttt bro... – user2978725 Dec 31 '13 at 05:51

0 Answers0