xamarin.android - 检查蓝牙 IsEnabled 使我的应用程序崩溃
问题描述
我正在创建一个 AndroidBluetoothService 来处理来自我的 Xamarin 应用程序的蓝牙交互。
在这个服务中,我使用了一个私有类变量:
private BluetoothAdapter ServiceAdapter;
然后我在构造函数中初始化它:
ServiceAdapter = BluetoothAdapter.DefaultAdapter;
然后,当我检查它是否已启用时:
bool enabled = ServiceAdapter.IsEnabled;
我收到一个导致我的应用程序崩溃的异常:
System.NotSupportedException
Message=Could not activate JNI Handle 0xbef405b8 (key_handle 0xdb031b8) of Java type 'crc6402525acf0275fedf/MainActivity' as managed type 'ArduinoSerial.MainActivity'.
其中 ArduinoSerial 是我的项目/应用程序的名称,而 MainActivity 是正在运行的活动。我已经对代码进行了注释和取消注释,以准确找出哪一行正在爆炸。不知道如何从这里开始,但我现在跳过这条线,只是假设它已启用。
解决方案
看来问题是由于应用程序没有蓝牙权限引起的。我添加了
到 AndroidManifest.xml 并解决了问题。
为一个简单的问题创建一个钝错误的方法。:(希望这对其他人有所帮助。
推荐阅读
- java - 如何使用自定义方法在链表的第 0 位插入节点?
- c++ - 由于类后的分号导致内部编译器错误
- node.js - EJS 中的 Header 部分问题
- python-3.x - LSTM Keras 中的多个功能
- sharepoint - 如何使用 SharePoint PnP 获取 SharePoint 2013 上的网站集列表
- javascript - If 语句查找数字字段是否留空或小数位数过多,但如果小数位仅为零则忽略
- flutter - Flutter 错误:- 调用 dispose 后不应使用 AnimationController 方法
- javascript - 检查字符串是否以提供的参数结尾
- php - Laravel 7 从数据库和磁盘中删除数组或单个图像 - 从数据库或磁盘中删除帖子但不关联图像
- python - InstaPy /“图片太少,跳过这个标签”