示例#1
0
 public override void OnReceive(Context c, Intent i)
 {
     if (ACTION_USB_PERMISSION.Equals(i.Action))
     {
         UsbDevice device = (UsbDevice)i.GetParcelableExtra(UsbManager.ExtraDevice);
         if (i.GetBooleanExtra(UsbManager.ExtraPermissionGranted, false))
         {
             if (device != null)
             {
                 //call method to set up device communication
                 try {
                     addDevice(device);
                 } catch (Exception e) {
                     Logger.Error("Failed to initialize device " + e.Message);
                 }
             }
         }
         else
         {
             Logger.Debug("Permission denied");
         }
     }
     else if (i.Action.Equals(UsbManager.ActionUsbDeviceAttached))
     {
         UsbDevice device = (UsbDevice)i.GetParcelableExtra(UsbManager.ExtraDevice);
         filterDevice(device);
     }
     else if (i.Action.Equals(UsbManager.ActionUsbDeviceDetached))
     {
         UsbDevice device = (UsbDevice)i.GetParcelableExtra(UsbManager.ExtraDevice);
         removeDevice(device);
     }
 }
示例#2
0
            public override void OnReceive(Context context, Intent intent)
            {
                string action = intent.Action;

                if (ACTION_USB_PERMISSION.Equals(action))
                {
                    lock (this)
                    {
                        UsbDevice device = (UsbDevice)intent
                                           .GetParcelableExtra(UsbManager.ExtraDevice);

                        if (intent.GetBooleanExtra(
                                UsbManager.ExtraPermissionGranted, false))
                        {
                            if (device != null)
                            {
                                // call method to set up device communication
                            }
                        }
                        else
                        {
                        }
                    }
                }
            }
示例#3
0
            //[MethodImpl(MethodImplOptions.Synchronized)]
            public override void OnReceive(Context context, Intent intent)
            {
                //intent.SetAction(ACTION_USB_PERMISSION);
                //intent.SetAction(UsbManager.ActionUsbDeviceAttached);
                //intent.SetAction(UsbManager.ActionUsbDeviceDetached);
                // Do stuff here.
                string value  = intent.GetStringExtra("key");
                string action = intent.Action;

                logMsg(DateTime.Now + " Line:219: Action name:" + action);
                if (ACTION_USB_PERMISSION.Equals(action))
                {
                    logMsg(DateTime.Now + " Line:219: ACTION_USB_PERMISSION1");
                    UsbDevice device = (UsbDevice)intent
                                       .GetParcelableExtra(UsbManager.ExtraDevice);
                    logMsg(DateTime.Now + " Line:219: ACTION_USB_PERMISSION Device" + device);
                    if (intent.GetBooleanExtra(
                            UsbManager.ExtraPermissionGranted, false))
                    {
                        if (device != null)
                        {
                            mReader.Open(device);
                            logMsg(DateTime.Now + " Line:219: ACTION_USB_PERMISSION OPEN");
                            new OpenTask().Execute(device);
                            byte[] buffer = toByteArray("02");
                            mReadKeyOption.TimeOut = buffer[0] & 0xFF;
                        }
                    }
                }
                else if (UsbManager.ActionUsbDeviceDetached.Equals(action))
                {
                    logMsg(DateTime.Now + " Line:219: ActionUsbDeviceDetached");
                    //// Update reader list
                    mReaderAdapter.Clear();
                    foreach (UsbDevice device1 in mManager.DeviceList.Values)
                    {
                        if (mReader.IsSupported(device1))
                        {
                            mReaderAdapter.Add(device1.DeviceName);
                        }
                    }

                    UsbDevice device = (UsbDevice)intent
                                       .GetParcelableExtra(UsbManager.ExtraDevice);
                    //logMsg(DateTime.Now + " Line:219: ActionUsbDeviceDetached::" + device);
                    if (device != null && device.Equals(mReader.Device))
                    {
                        // Clear slot items
                        mSlotAdapter.Clear();

                        // Close reader
                        System.Console.Write("Closing reader...");
                        new CloseTask().Execute();
                    }
                }
                else if (UsbManager.ActionUsbDeviceAttached.Equals(action))
                {
                    logMsg(DateTime.Now + " Line:268: ActionUsbDeviceAttached::");
                    //if (deviceName != null) {

                    // For each device
                    foreach (UsbDevice device1 in mManager.DeviceList.Values)
                    {
                        // Request permission
                        mManager.RequestPermission(device1,
                                                   mPermissionIntent);
                        //requested = true;
                        break;
                        // }
                    }

                    // }
                }
            }