首页 > 解决方案 > HM-10 和温度传感器的 BLE 连接问题:Android 应用程序使用 android studio 版本 3.1.4 和 API 15:Android 4.0.3 (IceCreamSandwich)

问题描述

我必须使用 android studio sdk 版本 3.1.4 设计一个 android 应用程序并在 API 15 上开发:Android 4.0.3 (IceCreamSandwich),它能够使用类似于 playstore 上的 BLE 终端应用程序的 HM 10 BLE 模块从 arduino 接收 csv 数据。BLE终端应用程序用于扫描附近的BLE设备,也用于串行通信。通过您的智能手机控制任何使用任何 BLE 模块(基于德州仪器 CC254x)的微控制器。此应用程序可以通过 BLE 发送和接收命令,因此您可以轻松调试硬件问题。以 ASCII 或 HEX 形式监控接收数据。以 ASCII 或 HEX 格式发送数据。目前我已经在 android studio 上导入了 BluetoothLEGATT 示例代码并安装了应用程序,我在其中获取数据但数据没有进入流我希望它显示在流中。我想以 csv 格式接收它。数据应采用流格式。在 arduino 方面,我以 csv 格式发送。

<?xml version="1.0" encoding="UTF-8"?>

<!--Copyright 2013 The Android Open Source ProjectLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License. -->

-<manifest android:versionName="1.0" android:versionCode="1" package="com.example.android.bluetoothlegatt" xmlns:android="http://schemas.android.com/apk/res/android">

<!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle -->


<!-- Declare this required feature if you want to make the app available to BLE-capabledevices only. If you want to make your app available to devices that don't support BLE,you should omit this in the manifest. Instead, determine BLE capability by usingPackageManager.hasSystemFeature(FEATURE_BLUETOOTH_LE) -->


<uses-feature android:required="true" android:name="android.hardware.bluetooth_le"/>

<uses-permission android:name="android.permission.BLUETOOTH"/>

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>


-<application android:theme="@android:style/Theme.Holo.Light" android:icon="@drawable/ic_launcher" android:label="@string/app_name">


-<activity android:name=".DeviceScanActivity" android:label="@string/app_name">


-<intent-filter>

<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>

</intent-filter>

</activity>

<activity android:name=".DeviceControlActivity"/>

<service android:name=".BluetoothLeService" android:enabled="true"/>

</application>

</manifest>

标签: androidarduinobluetooth-lowenergyandroid-studio-3.1.4

解决方案


低功耗蓝牙 (BLE) 在 4.3 版本中被引入 Android。因此,您的问题之一可能是 API 15:Android 4.0.3 (IceCreamSandwich)。尝试将最低 API 更改为 18。在 API 级别 21 之前,Lollipop android 使用 BlueZ 软件堆栈。尽管 BlueZ 工作正常,但它在 Android 4.3 上的 BLE 仍然存在一些稳定性问题,尤其是在保持连接时进行扫描。随着 Android API 21 版本的发布,使用了更稳定的 Bluedroid 软件堆栈,并改进了 BLE 的 API。


推荐阅读