This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ble.StateChanged += (s, e) => { | |
try { | |
switch (_ble.State) { | |
case BluetoothState.On: | |
page.DisplayAlert("Bluetooth Activado ", "Escaneando...", "OK"); | |
ScanDevicesCommand.Execute(null); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ICommand _desconnectCommand; | |
public ICommand DesconnectCommand => _desconnectCommand ?? (_desconnectCommand = new Command(async (item) => { | |
var device = item as IDevice; | |
try { | |
if(device.State == Plugin.BLE.Abstractions.DeviceState.Disconnected) { | |
throw new System.ArgumentException("Dispositivo no puede estar desconectado", "devicel.state"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ICommand _deviceSelectedCommand; | |
public ICommand DeviceSelectedCommand => _deviceSelectedCommand ?? (_deviceSelectedCommand = new Command(async (deviceselected) => { | |
await _adapter.StopScanningForDevicesAsync(); | |
Debug.WriteLine("Device Selected"); | |
var device = deviceselected as IDevice; | |
try { | |
await _adapter.ConnectToDeviceAsync(device); | |
await page.DisplayAlert("Conectado", $"Status {device.State}", "Ok"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ICommand _scanDevicesCommand; | |
public ICommand ScanDevicesCommand => _scanDevicesCommand ?? (_scanDevicesCommand = new Command(async () => { | |
Debug.WriteLine("Scan Devices..."); | |
IsRefreshing = true; | |
SelectionMode = SelectionMode.None; | |
try { | |
_adapter.ScanTimeout = 5000; | |
_adapter.ScanMode = ScanMode.Balanced; | |
DeviceCollection.Clear(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.RequestPermissions(new[] | |
{ | |
Manifest.Permission.AccessCoarseLocation, | |
Manifest.Permission.BluetoothPrivileged | |
}, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.marqzosvaldo.bleexample"> | |
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | |
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | |
<uses-permission android:name="android.permission.BLUETOOTH" /> | |
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> | |
</manifest> |