1. Download our Official Android App: Forums for Android!

Apps barcode and qr code programming

Discussion in 'Android Development' started by Sanjit singh, Jun 4, 2016.

  1. Sanjit singh

    Sanjit singh Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    24
    Joined:
    Jun 4, 2016

    Jun 4, 2016
    24
    0
    15
    Male
    m programming a caregiver app that involves barcode and qr code scanning for android. the main focus of the app is that it should only scan medication products. after it scans the meds full information should show, its name, information and should be saved in a folder on your phone to any specified location like gallery or anywhere. this is my code i have:

    package com.example.testing;



    import android.app.Activity;
    import android.app.AlertDialog;
    import android.content.ActivityNotFoundException;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Toast;

    public class MainActivity extends Activity {


    static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";


    @override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    }

    public void scanBar(View v){
    try{
    Intent intent = new Intent(ACTION_SCAN);
    intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
    startActivityForResult(intent, 0);
    }catch (ActivityNotFoundException e){
    showDialog(MainActivity.this, "No Scanner Found",
    "Download a scanner code activity?", "Yes", "No").show();

    }


    }

    public void scanQR(View v){
    try{
    Intent intent = new Intent(ACTION_SCAN);
    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
    startActivityForResult(intent, 0);
    }catch (ActivityNotFoundException e){
    showDialog(MainActivity.this, "No Scanner Found",
    "Download a scanner code activity?", "Yes", "No").show();
    }
    }

    private static AlertDialog showDialog(final Activity act,
    CharSequence title, CharSequence message,
    CharSequence buttonYes,
    CharSequence buttonNo) {

    AlertDialog.Builder dowloadDialog = new AlertDialog.Builder(act);
    dowloadDialog.setTitle(title).setMessage(message).setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {

    @override
    public void onClick(DialogInterface dialog, int which) {
    Uri uri = Uri.parse("market://search?q=pname:" +
    "com.google.zxing.client.android");

    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    try{
    act.startActivity(intent);
    } catch(ActivityNotFoundException e){

    }

    }
    }).setNegativeButton(buttonNo, new DialogInterface.OnClickListener() {

    @override
    public void onClick(DialogInterface dialog, int which) {


    }
    });

    return dowloadDialog.show();

    }
    @override
    protected 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, "Content:" + contents + "Format:" + format,
    Toast.LENGTH_LONG).show();
    }
    }
    }


    }

    this is my xml file:

    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:eek:rientation="vertical"
    tools:context="com.javacodegeeks.androidstartactivityforresultexample.ActivityOne" >

    <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center|top"
    android:layout_margin="20dp"
    android:text="Scan"
    android:textColor="#000000"
    android:textSize="30dp" />
    <Button
    android:id="@+id/scanner"
    android:layout_width="250dp"
    android:layout_height="80dp"
    android:layout_gravity="center"
    android:layout_margin="10dp"
    android:gravity="center"
    android:eek:nClick="scanQR"
    android:text="QR Code"
    android:textSize="18dp" >
    </Button>

    <Button
    android:id="@+id/scanner2"
    android:layout_width="250dp"
    android:layout_height="80dp"
    android:layout_gravity="center"
    android:layout_margin="10dp"
    android:gravity="center"
    android:eek:nClick="scanBar"
    android:text="Bar Code"
    android:textSize="18dp" >
    </Button>
    </LinearLayout>


    Can someone help me with the focus of scanning for one specific product which is medications and medications only. other products that are not medicines should say invalid. Thank you
     

    Advertisement

  2. Mikestony

    Mikestony ~30% Carbon Black ±
    Moderator
    Rank:
     #6
    Points:
    3,118
    Posts:
    29,287
    Joined:
    Sep 10, 2010

    Sep 10, 2010
    29,287
    23,445
    3,118
    Male
    Next to you
    Hiya @Sanjit singh !
    Welcome to AF:)
    I've moved your thread to the App Development forum for more focused help.

    I wish I could assist, but all that text is French to me :p
    Good luck !
     
    KOLIO and scary alien like this.
  3. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    Does you meds have a special character attached to it? i.e. M-39484730387457 would be a med while another bar code would be this C-394ufirr for a customer. Then if the barcode has a M in it allow the scanner to scan. But if it does not then say invalid code.
     
    Mikestony likes this.
  4. Sanjit singh

    Sanjit singh Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    24
    Joined:
    Jun 4, 2016

    Jun 4, 2016
    24
    0
    15
    Male
    what part of my code do i do that into. see im a beginner. i just started to learn
     
  5. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    First off lets figure out how your data is set up. Can you post an example of what one of the numbers look like that you are using to build the barcode.
    Also are you using a QR code or a barcode. They are similar but we will have to handle them differently.
    A QR code will have all the information in there so you will be able pull all of that out. A barcode can have that information but it will be encoded a little more
     
  6. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    Also take a look at this and how its set up. I used the zxing to generate a barcode and its way harder than reading.
    https://android-arsenal.com/details/1/387

    This will tell you how to set up the code and use it. Read though that and see if it makes sense.
     
  7. Sanjit singh

    Sanjit singh Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    24
    Joined:
    Jun 4, 2016

    Jun 4, 2016
    24
    0
    15
    Male
    I am using both barcode and qr code:
    This my code:



    import android.app.Activity;

    import android.app.AlertDialog;

    import android.content.ActivityNotFoundException;

    import android.content.DialogInterface;

    import android.content.Intent;

    import android.net.Uri;

    import android.os.Bundle;

    import android.view.View;

    import android.widget.Toast;



    public class MainActivity extends Activity {





    static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";





    @override

    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);



    }



    public void scanBar(View v){

    try{

    Intent intent = new Intent(ACTION_SCAN);

    intent.putExtra("SCAN_MODE", "PRODUCT_MODE");

    startActivityForResult(intent, 0);

    }catch (ActivityNotFoundException e){

    showDialog(MainActivity.this, "No Scanner Found",

    "Download a scanner code activity?", "Yes", "No").show();


    }



    }


    public void scanQR(View v){

    try{

    Intent intent = new Intent(ACTION_SCAN);

    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");

    startActivityForResult(intent, 0);

    }catch (ActivityNotFoundException e){

    showDialog(MainActivity.this, "No Scanner Found",

    "Download a scanner code activity?", "Yes", "No").show();

    }

    }



    private static AlertDialog showDialog(final Activity act,

    CharSequence title, CharSequence message,

    CharSequence buttonYes,

    CharSequence buttonNo) {


    AlertDialog.Builder dowloadDialog = new AlertDialog.Builder(act);

    dowloadDialog.setTitle(title).setMessage(message).setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {


    @override

    public void onClick(DialogInterface dialog, int which) {

    Uri uri = Uri.parse("market://search?q=pname:" +

    "com.google.zxing.client.android");


    Intent intent = new Intent(Intent.ACTION_VIEW, uri);

    try{

    act.startActivity(intent);

    } catch(ActivityNotFoundException e){


    }


    }

    }).setNegativeButton(buttonNo, new DialogInterface.OnClickListener() {


    @override

    public void onClick(DialogInterface dialog, int which) {




    }

    });


    return dowloadDialog.show();


    }

    @override

    protected 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, "Content:" + contents + "Format:" + format,

    Toast.LENGTH_LONG).show();

    }

    }

    }



    }
    xml file:
    <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:id="@+id/container"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:background="#ffffff"

    android:backgroundTint="@android:color/holo_blue_bright"

    android:eek:rientation="vertical"

    tools:context="com.javacodegeeks.androidstartactivityforresultexample.ActivityOne" >



    <TextView

    android:id="@+id/textView1"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_gravity="center|top"

    android:layout_margin="20dp"

    android:text="Scan"

    android:textColor="#000000"

    android:textSize="30dp" />



    <Button

    android:id="@+id/scanner"

    android:layout_width="250dp"

    android:layout_height="80dp"

    android:layout_gravity="center"

    android:layout_margin="10dp"

    android:backgroundTint="@android:color/holo_orange_dark"

    android:gravity="center"

    android:eek:nClick="scanQR"

    android:text="QR Code"

    android:textSize="18dp" >



    </Button>



    <Button

    android:id="@+id/scanner2"

    android:layout_width="250dp"

    android:layout_height="80dp"

    android:layout_gravity="center"

    android:layout_margin="10dp"

    android:backgroundTint="@android:color/holo_purple"

    android:gravity="center"

    android:eek:nClick="scanBar"

    android:text="Bar Code"

    android:textSize="18dp" >



    </Button>

    </LinearLayout>

    a number. one example i have is 8901296026793. but that number is not a medicine product. right now it scan anything. i only want for it to able to scan medicine products.
     
  8. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    You have to have an identifier to tell the system that its meds. So do all meds start with a 8 or anything special?
    What other barcodes does the product have on them. If its just one then that easy you don't have to worry about it then, but if there is multiple ones than you have to be able to differentiate between the two via a number or letter something that can tell the systems its a med.
     
  9. Sanjit singh

    Sanjit singh Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    24
    Joined:
    Jun 4, 2016

    Jun 4, 2016
    24
    0
    15
    Male
    as i said no i dont know what meds start with. i want it to have only one focus which are meds and i need help into telling my code how to do it. other numbers i have are 036632008404, 0826575000638, tec. random products are barcoded and qr coded. i just want it to have a focus on only scanning meds. nothing else. just meds.
     
  10. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    Thats what I am trying to help you figure out. Can you give a example Label that is attached to the meds. So we can see how everything is laid out. How many barcodes are on the label and qr codes as well
     
  11. Sanjit singh

    Sanjit singh Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    24
    Joined:
    Jun 4, 2016

    Jun 4, 2016
    24
    0
    15
    Male
    in this medicine Nyquil there is only one barcode and a small qr code laid on the top
     
  12. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    So its off the shelf meds. They won't have a special identifier on it, so you will need a database and look up the barcode number after the scan to get the information. So all you need from the scan is the number then link that number up to your database to download all the information you want off of that. Its pretty much going to be a walmart scanner that you will have to create.
    So each barcode will act as the key to get the products information. That way you can just send the key to the database and access the information that you want from there.

    Do you have a database of meds that your store is offering?
     
  13. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
  14. Sanjit singh

    Sanjit singh Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    24
    Joined:
    Jun 4, 2016

    Jun 4, 2016
    24
    0
    15
    Male
    barcode is on the bottom
    Thats fine but i dont ave the database of the meds my store is offering. i looked at the website and it is still the exact same code. that code doesnt have a spefic focus on scan. i just need help knowing wat code to use for medicine product scanning and where to put that code. the only focus the program should ahve for scanning is just medication products
     
  15. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    Does you scanner work? When you scan something what does the logcat say/give you?
     
  16. Sanjit singh

    Sanjit singh Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    24
    Joined:
    Jun 4, 2016

    Jun 4, 2016
    24
    0
    15
    Male
    yes it works fine. it gives the product number and stores in a file. the only thing i need is for it to scan one product only. whic hare medication products. only meds. the rest it should scan invalid.
     
  17. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    Can you show me what it prints out in the logcat where you products are. That what I would need to know Show me both a med and a nonmed scan if you would
     
  18. Sanjit singh

    Sanjit singh Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    24
    Joined:
    Jun 4, 2016

    Jun 4, 2016
    24
    0
    15
    Male
    It prints Found product then the number #.
    EX: Found product 8901296026793
     
  19. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
  20. Sanjit singh

    Sanjit singh Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    24
    Joined:
    Jun 4, 2016

    Jun 4, 2016
    24
    0
    15
    Male
    so now how do i add the database to my code so when i scan med it goes to that database.
    also lets say its scans something thats not a medicine. how doi make it print invalid product if the product it is barcode or qr code scanning is not a medicine.
     
  21. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    You will have to figure out which database is best for you. And once you scan a product if its is not in the database the API should send you a error message which means that the product is not in the database.
    To add the database to your code you have to get an endpoint for it like a url. This way you can ask send a get request with the barcode in as a parameter to the database and ask to see if the number is in the database. The database should send back the information that you can then parse it out seeing it will most likely be a json response. Go and pick a database based off your needs and I will help you get it into your project.
     
  22. Sanjit singh

    Sanjit singh Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    24
    Joined:
    Jun 4, 2016

    Jun 4, 2016
    24
    0
    15
    Male
    this is the datbase i like:
    http://www.product-open-data.com/search/
    so for htis database only medicine products from app should be scannable and saved to this database.
    so now that i know which one i want how do i program it to my project and make sure its only medicine that are scanned. other products likes books, games or non medication product related should print me invalid scan.
     
  23. Sanjit singh

    Sanjit singh Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    24
    Joined:
    Jun 4, 2016

    Jun 4, 2016
    24
    0
    15
    Male
    so i know barcode will work will qr code work as well.
     
  24. Sanjit singh

    Sanjit singh Newbie
    Thread Starter
    Rank:
    None
    Points:
    15
    Posts:
    24
    Joined:
    Jun 4, 2016

    Jun 4, 2016
    24
    0
    15
    Male
    this is what i did to my code. it takes to to the database:
    package com.example.testing;







    import android.app.Activity;

    import android.app.AlertDialog;

    import android.content.ActivityNotFoundException;

    import android.content.DialogInterface;

    import android.content.Intent;

    import android.net.Uri;

    import android.os.Bundle;

    import android.view.Gravity;

    import android.view.View;

    import android.widget.Toast;





    public class MainActivity extends Activity {





    static final String ACTION_SCAN = "com.google.zxing.client.android.SCAN";





    @override

    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);



    }



    public void scanBar(View v){

    try{

    Intent intent = new Intent(ACTION_SCAN);

    intent.putExtra("SCAN_MODE", "PRODUCT_MODE");

    startActivityForResult(intent, 0);

    }catch (ActivityNotFoundException e){

    showDialog(MainActivity.this, "No Scanner Found",

    "Download a scanner code activity?", "Yes", "No").show();


    }



    }


    public void scanQR(View v){

    try{

    Intent intent = new Intent(ACTION_SCAN);

    intent.putExtra("SCAN_MODE", "QR_CODE_MODE");

    startActivityForResult(intent, 0);

    }catch (ActivityNotFoundException e){

    showDialog(MainActivity.this, "No Scanner Found",

    "Download a scanner code activity?", "Yes", "No").show();

    }

    }



    private static AlertDialog showDialog(final Activity act,

    CharSequence title, CharSequence message,

    CharSequence buttonYes,

    CharSequence buttonNo) {


    AlertDialog.Builder dowloadDialog = new AlertDialog.Builder(act);

    dowloadDialog.setTitle(title).setMessage(message).setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {


    @override

    public void onClick(DialogInterface dialog, int which) {

    Uri uri = Uri.parse("market://search?q=pname:" +

    "com.google.zxing.client.android");


    Intent intent = new Intent(Intent.ACTION_VIEW, uri);

    try{

    act.startActivity(intent);

    } catch(ActivityNotFoundException e){


    }


    }

    }).setNegativeButton(buttonNo, new DialogInterface.OnClickListener() {


    @override

    public void onClick(DialogInterface dialog, int which) {




    }

    });


    return dowloadDialog.show();


    }

    @override

    protected 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, "Content:" + contents + "Format:" + format,

    Toast.LENGTH_LONG).show();

    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.product-open-data.com/search/"));

    startActivity(browserIntent);




    } else if (resultCode == RESULT_CANCELED) {

    // Handle cancel

    Toast toast = Toast.makeText(this, "Scan was Cancelled!", Toast.LENGTH_LONG);

    toast.setGravity(Gravity.TOP, 25, 400);

    toast.show();





    }

    }

    }

    }

    but now how do i make it print the product number on the search engine on the site and if lets say to test it if i scan something thats not a medication product how do we make it say invalid product.
     
  25. HeavensSentSword

    HeavensSentSword Well-Known Member
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    can you put your code in the code brackets its herd to read like that,
    What did the database return when you sent your get request?
     

Share This Page

Loading...