Skip to content

Instantly share code, notes, and snippets.

View marqzosvaldo's full-sized avatar
🏠
Working from home

marqzosvaldo

🏠
Working from home
  • GoStrategy
View GitHub Profile
@marqzosvaldo
marqzosvaldo / EventBluetoothState.cs
Last active December 13, 2019 05:06
Evento Estado de Bluetooth
_ble.StateChanged += (s, e) => {
try {
switch (_ble.State) {
case BluetoothState.On:
page.DisplayAlert("Bluetooth Activado ", "Escaneando...", "OK");
ScanDevicesCommand.Execute(null);
@marqzosvaldo
marqzosvaldo / CommandDisconnectDevice.cs
Created December 13, 2019 05:00
CommandDesconectarDispositivo
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");
}
@marqzosvaldo
marqzosvaldo / ConnectToDevice.cs
Created December 13, 2019 04:58
CommandConectarDispositivo.
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");
@marqzosvaldo
marqzosvaldo / CommandScanDevices.cs
Created December 13, 2019 04:49
CommandScanearDispositivos
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();
@marqzosvaldo
marqzosvaldo / MainActivity.cs
Created December 13, 2019 04:34
MainActivity.cs
this.RequestPermissions(new[]
{
Manifest.Permission.AccessCoarseLocation,
Manifest.Permission.BluetoothPrivileged
}, 0);
@marqzosvaldo
marqzosvaldo / AndroidManifest.xml
Created December 13, 2019 04:18
AndroidManifestPermisos
<?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>