2 Replies Latest reply on Aug 2, 2016 10:23 AM by Mike Bedford

    Modifying app to use EMDK after KitKat release on MC67NA

    Mike Bedford

      Hello All, I had already created an Android app to run on the MC67NA which previously was only shipped with Jelly Bean. Because the EMDK only supported KitKat and above, I had to do all barcode scanning via DataWedge. However, now that KitKat has been released and I now have a device running KitKat, I am modifying the app to use the EMDK instead of DataWedge. My question is, while I see all the samples provided and they do help get started, they are also geared towards a single layout/Activity application. My existing application has a main Activity which serves as a container for fragments and a view pager. I need to do scanning on several of the fragments when they are the active page in the view pager. The DataWedge made this easy because I didn't have to worry about any of that, it would just scan to the field which had focus.

       

      All that said, what is the best way to implement the EMDK barcode scanner for this setup? I know many people are against a singleton class, but I was thinking about going down this road. Create a singleton to implement the scanner when the app starts up. From each fragment, I could then get the instance to the scanner class and use it. Can anybody give me some advice on this? I also don't know how exactly to also register the event handlers in the singleton (assuming this is the best method) and then have those events fire on the fragments.

       

      I do want to get away from DataWedge and integrate the EMDK for various reasons.

       

      Last, on a related note, I have started to code this approach and am getting an exception on this line:

       

      EMDKResults results = EMDKManager.GetEMDKManager(Application.Context, this);
      

       

      The exception states:

       

      Java.Lang.ClassNotFoundException: Didn't find class "com.symbol.emdk.EMDKManager" on path: DexPathList[[zip file "/data/app/PocketPacTracAndroid.PocketPacTracAndroid-2.apk"],nativeLibraryDirectories=[/data/app-lib/PocketPacTracAndroid.PocketPacTracAndroid-2, /vendor/lib, /system/lib]]

      This happens even though I have included the reference:

       

      Thanks in advance!

       

      Mike

       

      Message was edited by: Michael Bedford I wanted to edit my post, it is my own fault for not posting the whole code and if I had, I think you all would have seen my issue. I missed this one completely, however, wanted to update this thread in case anybody else has the same issue. The problem with the exception is I did not include the following lines in my manifest. So note, not including these lines will cause the error I indicated above:

       

      1. In the <application></application> tags, you must have this line: <uses-library android:name="com.symbol.emdk" />

      2. Just under the uses-sdk tag, you must have this line: <uses-permission android:name="com.symbol.emdk.permission.EMDK" />

      Thanks!

        • Re: Modifying app to use EMDK after KitKat release on MC67NA
          Pietro Francesco Maggi

          Hi Michael,

          the error you see may be due to a missing/wrong version of the EMDK runtime of the device. In any case is always best to install the latest one.

           

          Regarding how to integrate the EMDK in your project, the idea to have all the barcode handling done in a single class that then send messages internally to the active UI object looks interesting to me.

          As I wrote, more than a singleton I would prefer something similar to a service and some kind of message bus.

           

          Regarding how to have a C# class implement the EMDK listener interface, there has been a discussion sometime ago about this:

          Re: IntPtr problem

           

          Ciao

          ~Pietro

            • Re: Modifying app to use EMDK after KitKat release on MC67NA
              Mike Bedford

              Hello Pietro,

               

              Thank you for the reply. As for my error, I have edited my original post above to show what the resolution is. It was my fault, forgot the necessary lines in the Android Manifest and once added, that fixed the error. Again, that is described in my original post in case anybody else has the same issue/error.

               

              Second, thank you for the link you provided to the IntPrt problem. I ALSO had that issue and your link allowed me to resolve it before I had to ask that question as well. Basically, here is what I have learned for anyone else. If you are integrating this into your main activity and therefore, one of the items you are inheriting from is "Activity", then you will be fine just inheriting from the IEMDKListener. HOWEVER, if you are creating this scanner in a separate class (like I am doing), you will not be inheriting from "Activity" and the first thing you will do is inherit from the IEMDKListener. In this case, the interface will want to force you to implement an IntPtr method called "Handle". What you need to do, as explained in the link provided by Pietro, is also inherit from Java.Lang.Object and then, the IEMDKListener interface will not force you to implement the IntPtr method. This is what you want. So, you should look like this if in your activity:

               

              public class MyScannerActivity : Activity, EMDKManager.IEMDKListener
              

               

              Otherwise, if you are creating a wrapper class, outside of your activity, you will do this:

               

              public class MyScannerClass : Java.Lang.Object, EMDKManager.IEMDKListener
              

               

              So, that solves two big problems.

               

              I am now still on the path of the best practice to implement this as a wrapper class. Understood on your comments on a service as well. Here is what I have/want. I have a main activity the launches and is active/running any time the user is using the app. As long as that activity is running, I want to have access to the scanner. However, I access the scanner from multiple fragments that are in a view pager from that main activity.

               

              Therefore, what I am looking at right now is a singleton class that will be called on activity startup to do all of the init functions and get the scanner all setup and configured. Then, when a fragment is active in the view pager, I can get the instance to the class and therefore, access the scanner.

               

              I guess as I type that out, it seems a little clunky. Thoughts?

               

              Thanks!

               

              Mike