7 Replies Latest reply on Mar 1, 2016 7:01 AM by Giovanni Ferrari

    IntPtr problem

    Giovanni Ferrari

      we are developing our first app on motorola mc9200 (android) with visual studio, and we start explore the functionality with EMDK SDK, we looked examples and is all quite ok, but now we need to move the IEMDKListener interface from the main activity to one specialized class, we have implemented the interface IEMDKListener on class,

       

        public class BarCode : IDisposable, EMDKManager.IEMDKListener

      ....

       

      but requiere IntPtr Handle property, how to implement it?

       

              public IntPtr Handle

              {

                  get

                  {

                      return ??;

                  }

              }

       

      there are example of this situation?

       

      another question, is possible enable/disable the led on device? we need to signal particular situation.

       

      thanks

        • Re: IntPtr problem
          Billie Hecox

          Hello Giovanni,

               As of now, we have no EMDK for Xamarin examples that separate the IEMDKListener from the Activity. To help understand what you are trying to accomplish, could you included a sample of your code? I'm not sure I understand what you need to do.

           

          As for the LED control, you would need to use the standard Android Notification APIs ( or the xamarin.android equivalent ) not the EMDK.

            • Re: IntPtr problem
              Giovanni Ferrari

              when i specify the IEMDKListener interface (to my class) i must add the

              EMDKManager.IEMDKListener.OnClosed() & EMDKManager.IEMDKListener.OnOpened(),

              but, visual studio signal error and specify that need also 'Handle' interface member (as you can see on the image)

              i think that Handle must point to EMDKManager.IEMDKListener.OnOpened() interface function, so when the IEMDKListener

              finish preparing can call OnOpened().

              the problem for me is to know the correct way to do this

              hope this time explained better!

               

              zebra.png

               

              extract of the class:

               

              public class BarCode : EMDKManager.IEMDKListener

                  {

                      private Scanner scanner = null;

                      private EMDKManager _emdkManager = null;

                      private BarcodeManager barcodeManager = null;

               

                public EMDKResults PrepareDevice(bool enableScanner)

                      {

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

                          _enableScanner = enableScanner;

               

                          return results;

                      }

               

                      public BarCode()

                      {

                      }

               

                      public IntPtr Handle

                      {

                          get

                          {

                              LogHandler counter = new LogHandler(OnOpened);

               

                              //// Delegate untypedManagedMethod = (Delegate)counter;

               

                              IntPtr nativeThunk = Marshal.GetFunctionPointerForDelegate(counter);

               

                return nativeThunk;

                          }

                      }

               

                       [UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.StdCall, SetLastError = true)]

                      public delegate void LogHandler(EMDKManager emdkManager);

               

                      void EMDKManager.IEMDKListener.OnClosed()

                      {

                          ReleaseResource();

                      }

               

               

                      static void OnOpened(EMDKManager emdkManager)

                      {

                          string s = "";

                      }

               

               

                      void EMDKManager.IEMDKListener.OnOpened(EMDKManager emdkManager)

                      {

                          _emdkManager = emdkManager;

                // .......

                      }

                }

               

              we make this class becouse we use EMDK on 2 different part of the program, so, to make things 'standard' we prefer make this class, is more difficult mantain the same code in 2 different part (maybe in the future become 3..)

            • Re: IntPtr problem
              Giovanni Ferrari

              noone can help?

              • Re: IntPtr problem

                Hi Giovanni,

                 

                Sorry for taking long and hope this resolves your issue. Attached the modified sample. Basically you need to extend the class from Java.Lang.Object and remove Dispose and Handle functions generated from interface as it is taken from Object.

                 

                class Barcode: Java.Lang.Object, EMDKManager.IEMDKListener

                 

                This is a generic Xamarin usage query and explained in Xamarin docs: Android Callable Wrappers - Xamarin

                 

                Please get back to us if this is not resolving your issue.

                 

                Thanks,

                Charith.

                2 of 2 people found this helpful
                • Re: IntPtr problem
                  Giovanni Ferrari

                  thanks for the example, we start change the class..

                   

                  about the leds on mc9200, i not mean flash led or similar (like on regular telephone), the mc9200 have led (orange) for battery (and flash when charging), also red led (3) that signal when barcode is not decoded and 3 leds (green) that indicate barcode recognized, i ask if is possible control this leds