c# - Xamarin C# , I Cant Run Plugin.BLE Codes
问题描述
I'm trying to make a very simple and basic mobile app for controlling my Arduino with Bluetooth. Don't have many C# experiences, but it was going well until the Bluetooth part comes. I've searched everywhere and found this https://github.com/xabre/xamarin-bluetooth-le and started to do instructions in the readme. But I've got errors every time.
first, I copied these codes to androidmanifest.xml
<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" />
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
after that, I added these codes to mainpage.xml.cs
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
var ble = CrossBluetoothLE.Current;
var adapter = CrossBluetoothLE.Current.Adapter;
var state = ble.State;
}
}
But that caused 2 errors: Error CS0103 The name 'CrossBluetoothLE' does not exist in the current context BlueT
and I added using Plugin.BLE; so errors disappeared. and I continued to write;
adapter.DeviceDiscovered += (s,a) => deviceList.Add(a.Device);
await adapter.StartScanningForDevicesAsync();
after I paste these, I got that errors:
Error CS4033 The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task Error CS0103 The name 'deviceList' does not exist in the current context
I tried everything but couldn't solve this problem, and I'm sorry like I said, don't have many # or Android programming experiences, just want to send these slider and button data to my Arduino: This is my mobile controller app
解决方案
推荐阅读
- c# - 无法使用 github 操作连接到 SQL Server
- excel - 如何让excel等待工作簿打开
- regex - matlab:截断大文本并附加'...'
- javascript - 排序对象键以匹配另一个对象键
- vba - 使用 vb 从 PDF 中提取富文本字段到 MS Access
- c# - 将二进制数据转换为 gzip 文件并解压缩为字符串 c#
- java - Apache Flink 如何将备用键与主键映射和匹配到一个键控流
- huggingface-transformers - 如何将多个标签传递给 Huggingface 转换器 Trainer
- docker - 有没有办法在 yaml 中定义 Compose Swarm 所在的命名空间?
- sql - where 子句和使用关联对象来提高性能之间有什么区别吗