예제 #1
0
        override protected void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Create a BarcodeManager.
            manager = new BarcodeManager();
            SetContentView(Resource.Layout.Main);

            // setup button
            Button btn = (Button)FindViewById(Resource.Id.button1);

            btn.Click += delegate
            {
                StartSettingsActivity();
            };

            // Pass it to ScannerProperties class.
            // ScannerProperties cannot be instatiated directly, instead call edit.
            configuration = ScannerProperties.Edit(manager);

            // Now we can change some Scanner/Device configuration parameters.
            // These values are not applied, as long as store method is not called.
            configuration.Code39.Enable.Set(true);
            configuration.Code39.EnableChecksum.Set(true);
            configuration.Code39.FullAscii.Set(true);
            configuration.Code39.Length1.Set(20);
            configuration.Code39.Length2.Set(2);
            configuration.Code39.LengthMode.Set(LengthControlMode.TwoFixed);
            configuration.Code39.SendChecksum.Set(false);
            configuration.Code39.UserID.Set('x');

            configuration.Code128.Enable.Set(true);
            configuration.Code128.Length1.Set(6);
            configuration.Code128.Length2.Set(2);
            configuration.Code128.LengthMode.Set(LengthControlMode.Range);
            configuration.Code128.UserID.Set('y');

            if (configuration.QrCode.IsSupported)
            {
                configuration.QrCode.Enable.Set(false);
            }

            // Change IntentWedge action and category to specific ones.
            configuration.IntentWedge.Action.Set("com.datalogic.examples.decode_action");
            configuration.IntentWedge.Category.Set("com.datalogic.examples.decode_category");

            // From here on, we would like to get a return value instead of an exception in case of error
            ErrorManager.EnableExceptions(false);

            // Now we are ready to store them
            // Second parameter set to true saves configuration in a permanent way.
            // After boot settings will be still valid.
            int errorCode = configuration.Store(manager, true);

            // Check return value.
            if (errorCode != ConfigException.Success)
            {
                Log.Error(LOGTAG, "Error during store", ErrorManager.LastError);
            }
        }
        private void MyClickedItemListener(object sender, RadioGroup.CheckedChangeEventArgs e)
        {
            // Handle errors through java Exceptions
            ErrorManager.EnableExceptions(true);

            try
            {
                // get the current settings from the BarcodeManager
                configuration = ScannerProperties.Edit(manager);
                // disables KeyboardWedge
                configuration.KeyboardWedge.Enable.Set(false);
                // enable wedge intent
                configuration.IntentWedge.Enable.Set(true);

                switch (e.CheckedId)
                {
                case Resource.Id.radioBroadcast:
                    // set wedge intent action and category
                    configuration.IntentWedge.Action.Set(ACTION_BROADCAST_RECEIVER);
                    configuration.IntentWedge.Category.Set(CATEGORY_BROADCAST_RECEIVER);
                    // set wedge intent delivery through broadcast
                    configuration.IntentWedge.DeliveryMode.Set(IntentDeliveryMode.Broadcast);
                    configuration.Store(manager, false);
                    break;

                case Resource.Id.radioStartActivity:
                    // set wedge intent action and category
                    configuration.IntentWedge.Action.Set(ACTION);
                    configuration.IntentWedge.Category.Set(CATEGORY);
                    // intent delivery startActivity
                    configuration.IntentWedge.DeliveryMode.Set(IntentDeliveryMode.StartActivity);
                    configuration.Store(manager, false);
                    break;
                }
            }
            catch (Exception exception) //catch any errors that occured.
            {
                if (exception is ConfigException)
                {
                    ConfigException ex = (ConfigException)exception;
                    Log.Info(this.GetType().Name, "Error while retrieving/setting properties:" + exception.Message);
                }
                else if (exception is DecodeException)
                {
                    DecodeException ex = (DecodeException)exception;
                    Log.Info(this.GetType().Name, "Error while retrieving/setting properties:" + exception.Message);
                }
                else
                {
                    Log.Info(this.GetType().Name, "Error while retrieving/setting properties:" + exception.Message);
                }
            }
        }