protected override void OnCreate(Bundle savedInstanceState) { RequestWindowFeature(WindowFeatures.NoTitle); base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_set_characteristic_value); gatt = SingleGattService.GetInstance().CurGatt; service = SingleGattService.GetInstance().CurService; characteristic = SingleGattService.GetInstance().CurCharacteristic; callBack = SingleGattService.GetInstance().CurCallback; back = FindViewById <Button>(Resource.Id.settings_back); setValue = FindViewById <Button>(Resource.Id.settings_set_value); registNotify = FindViewById <Button>(Resource.Id.settings_regist_char_notify); unregistNotify = FindViewById <Button>(Resource.Id.settings_unregist_char_notify); valueHex = FindViewById <TextView>(Resource.Id.settings_value_hex); valueStr = FindViewById <TextView>(Resource.Id.settings_value_str); valueInput = FindViewById <EditText>(Resource.Id.settings_value_input); back.SetOnClickListener(this); setValue.SetOnClickListener(this); registNotify.SetOnClickListener(this); unregistNotify.SetOnClickListener(this); InitView(); }
private void OnDeviceConnect() { Log.Error("dana.ye->xamarin->bt", "手动点击按钮来停止扫描周围的蓝牙设备"); btAdapter.CancelDiscovery(); /*try * { #pragma warning disable CS0618 // 类型或成员已过时 * btAdapter.StopLeScan(bleScanCallback); #pragma warning restore CS0618 // 类型或成员已过时 * } * catch (Exception e) * { * Log.Error("dana.ye->xamarin->bt", "stopLeScan时出错 : " + e.Message); * }*/ handler.RemoveCallbacks(action); if (gatt != null) { gatt.Disconnect(); gatt.Close(); } Log.Error("dana.ye->xamarin->bt", "即将进行BLE的设备连接"); String addr = searchedDevices[adapter.GetChooseItem()].Address; SingleGattService.GetInstance().Address = addr; BluetoothDevice device = btAdapter.GetRemoteDevice(addr); GattCallBack mGattCallback = new GattCallBack(this); SingleGattService.GetInstance().CurCallback = mGattCallback; if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.M) { Log.Error("dana.ye->xamarin->bt", "SdkInt >= M"); gatt = device.ConnectGatt(this, false, mGattCallback, BluetoothTransports.Le); } else { Log.Error("dana.ye->xamarin->bt", "SdkInt < M"); gatt = device.ConnectGatt(this, false, mGattCallback); } }
protected override void OnCreate(Bundle savedInstanceState) { RequestWindowFeature(WindowFeatures.NoTitle); base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_characteristics); characteristics = new List <BluetoothGattCharacteristic>(); gatt = SingleGattService.GetInstance().CurGatt; service = SingleGattService.GetInstance().CurService; callBack = SingleGattService.GetInstance().CurCallback; characteristicsList = FindViewById <GridView>(Resource.Id.characteristics_list); back = FindViewById <Button>(Resource.Id.characteristics_back); refreshCharacteristics = FindViewById <Button>(Resource.Id.characteristics_refresh); stepintoCharacteristics = FindViewById <Button>(Resource.Id.characteristics_stepinto); adapter = new CharacteristicsAdapter(this, characteristics); characteristicsList.Adapter = adapter; characteristicsList.OnItemClickListener = this; back.SetOnClickListener(this); refreshCharacteristics.SetOnClickListener(this); stepintoCharacteristics.SetOnClickListener(this); RefreshCharacteristics(); }