public static RadioStatus ToRadioStatus(this Android.Bluetooth.State status) { switch (status) { case Android.Bluetooth.State.On: return(RadioStatus.On); case Android.Bluetooth.State.TurningOff: case Android.Bluetooth.State.TurningOn: case Android.Bluetooth.State.Off: return(RadioStatus.Off); default: return(RadioStatus.Unknown); } }
//--- IBluetoothRadio TestRadioStates(RadioModes expectedModes, RadioMode expectedMode, HardwareStatus expectedStatus, Android.Bluetooth.State state, Android.Bluetooth.ScanMode scanMode) { var values = new AndroidMockValues { Radio_Address = "10:23:45:67:89:ab", Radio_Name = "radio2222", Radio_State = state, Radio_ScanMode = scanMode, }; var f = AndroidTestInfra.Init(values); var r = f.DoGetPrimaryRadio(); // Assert.AreEqual(expectedMode, r.Mode, "r.Mode"); Assert.AreEqual(expectedModes, r.Modes, "r.Modes"); Assert.AreEqual(expectedStatus, r.HardwareStatus, "r.HardwareStatus"); return(r); }
public BtStateChangedEventArgs(int state) { BtState = (Android.Bluetooth.State)state; }
public BluetoothPrinterService() { BluetoothLowEnergy ble = new BluetoothLowEnergy(); Android.Bluetooth.BluetoothAdapter ba = null; try { ba = Android.Bluetooth.BluetoothAdapter.DefaultAdapter; if (null != ba) { try { Android.Bluetooth.State state = ba.State; } catch (Exception exc) { Android.Widget.Toast.MakeText ( Android.App.Application.Context, "Add bluetooth permission", Android.Widget.ToastLength.Long ).Show(); } } } catch (Exception exc) { string msg = "if this fails - AndroidManifest.xml"; LoggerService.WriteLine(msg); } if (ba == null) { LoggerService.WriteLine("BluetoothAdapter == null"); return; } if (!ba.IsEnabled) { LoggerService.WriteLine("Bluetooth adapter is not enabled."); } foreach (var bd in ba.BondedDevices) { LoggerService.WriteLine(bd.Name); } string device_name = "Qsprinter"; Android.Bluetooth.BluetoothDevice device = ( from bd in ba.BondedDevices where bd.Name == device_name select bd ).FirstOrDefault(); if (device == null) { LoggerService.WriteLine("Bluetooth device not found = " + device_name); } Android.OS.ParcelUuid[] uuids = device.GetUuids(); string uuid = uuids[0].ToString() //Guid.NewGuid().ToString() ; _socket = device .CreateInsecureRfcommSocketToServiceRecord(Java.Util.UUID.FromString(uuid)) //.CreateRfcommSocketToServiceRecord (Java.Util.UUID.FromString (uuid)) ; try { _socket.Connect(); if (_socket.IsConnected) { LoggerService.WriteLine("Bluetooth socket connected "); } } catch (Exception exc) { // [BluetoothUtils] isSocketAllowedBySecurityPolicy start : device null // [BluetoothSocket] GlobalConfig.GLOBALCONFIG_BT_IT_POLICY_FEATURE = true // [BluetoothAdapter] getBluetoothService() called with no BluetoothManagerCallback // [BluetoothSocket] connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[78]} } byte[] data_bytes = System.Text.Encoding.UTF8.GetBytes("Bluetooth created"); // Write data to the device //await try { _socket.OutputStream.WriteAsync(data_bytes, 0, data_bytes.Length); } catch (Exception exc) { } return; }