Exemplo n.º 1
0
        /**
         * Enable or disable Nfc, using com.datalogic.device.nfc.NfcManager.
         */
        public void SetEnableNfc(bool enable)
        {
            bool previous = ErrorManager.AreExceptionsEnabled();

            ErrorManager.EnableExceptions(false);
            ErrorManager.ClearErrors();

            int error = new Com.Datalogic.Device.Nfc.NfcManager().EnableNfcAdapter(enable);

            if (error != DeviceException.Success)
            {
                Log.Error(this.LocalClassName, "Error while setting NFC", ErrorManager.LastError);
            }
            ErrorManager.EnableExceptions(previous);
        }
        /**
         * Use LocationManager to set the gps as enabled (true), or disabled
         * (false).
         */
        public void SetGPSState(bool enable)
        {
            LocationManager gps = null;

            // Store previous exception preference.
            bool previous = ErrorManager.AreExceptionsEnabled();

            // We want to be notified through an exception if something goes wrong.
            ErrorManager.EnableExceptions(true);
            try
            {
                gps = new LocationManager();
                gps.SetLocationMode(enable ? LocationMode.SensorsAndNetwork : LocationMode.Off);
            }
            catch (DeviceException e1)
            {
                // Just in case we get an error.
                Log.Error(this.LocalClassName, "Exception while switching location mode ", e1);
            }
            // Set previous value.
            ErrorManager.EnableExceptions(previous);
        }