Click here to Skip to main content
15,850,685 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey, im developing a shopping assistant app that scans a barcode and gets program data and returns the location of the store with the lowest price.. ive found sending an intent to zxing is the easiest way to do this but for some reason it doesnt respond to the intent. At first it would crash the app, then i added the exception handling code by copying and pasting what i found on stack exchange (i even replaced my code for sending the intent to ensure i made no mistakes) but it still doesnt work, it just raises an exception and opens the store, so if you could assist with a step by step tutorial or guide on integrating it into the project itself or help me fix this i'd be very grateful.. here is the code:

Java
@Override
   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_qrreciever);
   }

   @Override
   protected void onStart (){
       super.onStart();
       try{

           //call zxing qr scan
           Intent GetEan = new Intent(Intent.ACTION_SEND);
           GetEan.setType("com.google.zxing.client.android.SCAN");
           GetEan.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
           GetEan.putExtra("SCAN_MODE", "PRODUCT_MODE");
           startActivityForResult(GetEan, 0);

       } catch (Exception e) {

           //Prompt asking for permission to go to store
           FrameLayout StorePrompt = (FrameLayout) findViewById(android.R.id.custom);
           //StorePrompt.addView(myView, new WindowManager.LayoutParams(MATCH_PARENT, WRAP_CONTENT));

           Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
           Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
           startActivity(marketIntent);
       }



   }


   @Override
   public boolean onCreateOptionsMenu(Menu menu) {
       // Inflate the menu; this adds items to the action bar if it is present.
       getMenuInflater().inflate(R.menu.menu_qrreciever, menu);



       return true;
   }

   @Override
   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
               Log.i("App", "Scan unsuccessful");
           }
       }
   }
Posted
Updated 16-Apr-15 22:20pm
v2
Comments
Darren_vms 2-Apr-15 5:06am    
Is zxing (barcode scanner) installed ?
Does it work standalone ?
Member 10287010 2-Apr-15 6:09am    
yes it's installed and yes it works standalone, and it was able to receive an intent from google authenticator. I just don't know what to do now :/
Darren_vms 2-Apr-15 7:53am    
so it works but you don't know what to do with the returned barcode scan ?
Member 10287010 2-Apr-15 8:22am    
no it worked with authenticator, but doesn't work with my app, i send the intent but it raises an exception.. hence the catch block catches it and opens the app store
JoCodes 17-Apr-15 3:48am    
Whats the Exception you are getting in the catch block?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900