Exemple #1
0
 public stateChangeListner(Com.Acs.Smartcard.Reader _reader, ReadKeyOption _mReadKeyOption, MainActivity _main)
 {
     main = _main;
     //   main = new MainActivity();
     mReader        = _reader;
     mReadKeyOption = _mReadKeyOption;
 }
Exemple #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            CallStack = new StackFrame(1, true);
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);
            mManager = (UsbManager)this.Application.GetSystemService(Context.UsbService);
            // Initialize reader
            mReader = new Com.Acs.Smartcard.Reader(mManager);


            // Initialize reader spinner
            mReaderAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem);

            foreach (UsbDevice device in mManager.DeviceList.Values)
            {
                if (mReader.IsSupported(device))
                {
                    mReaderAdapter.Add(device.DeviceName);
                }
            }
            stateChangeListner change = new stateChangeListner(mReader, mReadKeyOption, this);

            // Com.Acs.Smartcard.Reader.IOnStateChangeListener onStateChangeListener =new ;

            mReader.SetOnStateChangeListener(change);


            mReaderSpinner         = FindViewById <Spinner>(Resource.Id.main_spinner_reader);
            mReaderSpinner.Adapter = mReaderAdapter;

            mPermissionIntent = PendingIntent.GetBroadcast(this, 0, new Intent(
                                                               ACTION_USB_PERMISSION), 0);
            //IntentFilter filter = new IntentFilter();
            //filter.AddAction(ACTION_USB_PERMISSION);
            //filter.AddAction(UsbManager.ActionUsbDeviceDetached);
            //filter.AddAction(UsbManager.ActionUsbDeviceAttached);
            txtview = FindViewById <TextView>(Resource.Id.txtview);
            //RegisterReceiver(receiver, intent);
            //TextView txt = FindViewById<TextView>(Resource.Id.txtview);
            //txt.Text = "";
            try
            {
                mReceiver    _receiver = new mReceiver();
                IntentFilter filter    = new IntentFilter();
                filter.AddAction(ACTION_USB_PERMISSION);
                filter.AddAction(UsbManager.ActionUsbDeviceDetached);
                filter.AddAction(UsbManager.ActionUsbDeviceAttached);

                RegisterReceiver(_receiver, filter);


                //RegisterReceiver(_receiver, new IntentFilter(ACTION_USB_PERMISSION));
                //RegisterReceiver(_receiver, new IntentFilter(UsbManager.ActionUsbDeviceDetached));
                //RegisterReceiver(_receiver, new IntentFilter(UsbManager.ActionUsbDeviceAttached));

                ////var intent = new Intent(this, typeof(mReceiver));
                //var intent = new Intent(this, receiver.Class);
                //intent.SetAction(ACTION_USB_PERMISSION);
                //intent.SetAction(UsbManager.ActionUsbDeviceDetached);
                //intent.SetAction(UsbManager.ActionUsbDeviceAttached);
                // Android.Support.V4.Content.LocalBroadcastManager.GetInstance(this).SendBroadcast(intent);
                //SendBroadcast(intent);
                // txt.Text = "done";
                // ****** OnStateChangeListener ******
                // this.onStateChange(0);
            }
            catch (SecurityException ex)
            {
                txtview.Text = ex.Message.ToString();
            }

            mSlotAdapter         = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem);
            mSlotSpinner         = FindViewById <Spinner>(Resource.Id.main_spinner_slot);
            mSlotSpinner.Adapter = mSlotAdapter;

            string deviceName = (string)mReaderSpinner.SelectedItem;

            if (deviceName != null)
            {
                foreach (UsbDevice device in mManager.DeviceList.Values)
                {
                    if (deviceName.Equals(device.DeviceName))
                    {
                        mManager.RequestPermission(device, mPermissionIntent);
                        break;
                    }
                }
            }
        }