我们有一款应用程序使用蓝牙低功耗 (BLE) 技术与活动跟踪器等硬件设备进行通信。
所有支持 BLE 的手机均可进行通信,但当我们尝试将追踪器与华为手机连接时,它根本无法工作。
流程如下:
以下是显示问题的日志:
I/Bluetooth: BtGatt.GattService:onConnected() - clientIf=6, connId=0, address=E6:4F:92:69:B7:95
I/Bluetooth: BluetoothProfileService:isAvailable(), mStartError=false, mCleaningUp=false
BluetoothGatt Check Status and NewState: 133|0
I/Bluetooth: BtGatt.GattService:clientDisconnect() - address=E6:4F:92:69:B7:95, connId=null
Run Code Online (Sandbox Code Playgroud)
我们还使用“nRF Connect”应用程序进行了测试,在该应用程序中,它也提供了状态为 133(蓝牙 Gatt 故障)的断开回调。请查找随附的屏幕截图。
如果有人遇到同样的情况,可以帮助我们吗?
android bluetooth bluetooth-lowenergy android-bluetooth huawei-mobile-services
状态 40 代表什么?我正在尝试连接到 android 蓝牙应用程序中的设备并获取状态:40?该值是十进制还是十六进制?
如果它是十六进制蓝牙规范,则说明该错误:
COARSE CLOCK ADJUSTMENT REJECTED BUT WILL
TRY TO ADJUST USING CLOCK DRAGGING (0x40)
The Coarse Clock Adjustment Rejected but Will Try to Adjust Using Clock
Dragging error code indicates that the master, at this time, is unable to make a
coarse adjustment to the piconet clock, using the supplied parameters. Instead
the master will attempt to move the clock using clock dragging.
Run Code Online (Sandbox Code Playgroud)
否则,如果它是十进制,它会这样说;
INSTANT PASSED (0x28)
The Instant Passed error code indicates that an …
Run Code Online (Sandbox Code Playgroud) 我正在使用开源的 Fluoride 堆栈开发 BLE。是否有任何文档或注释可以帮助我理解 Fluoride 堆栈的架构?任何有关此问题的帮助将不胜感激。
bluetooth core-bluetooth bluetooth-lowenergy android-bluetooth bluetooth-gatt
我目前正在设计一个简单的室内定位项目来评估蓝牙 5.1 标准的可能性。我想使用的功能是蓝牙 5.1 中引入的 AoA(到达角度)。
根据该标准,AoA 允许通过近似角度并测量定位器/接收器 (rx) 上的 RSSI 来测量发射设备 (tx) 的位置。由于AoA是5.1中新实现的功能,因此我理解rx需要支持5.1蓝牙标准。发射装置怎么样?它需要支持的最低蓝牙版本是多少?我可以使用 4.x BLE 信标(或模拟信标的 Android/iOS 设备)来实现此目的吗?
bluetooth core-bluetooth bluetooth-lowenergy android-bluetooth ios-bluetooth
好吧,我知道已经有人问过很多类似的问题,但到目前为止没有任何效果。我已经尝试了所有 mediaSessionCompat 方法和回调,但没有运气。我已经阅读了文档,但它非常模糊,尤其是关于新实践。我基本上想覆盖蓝牙耳机的媒体按钮并停止默认音乐播放器的播放。
编辑:因此,在深入研究文档后,我得出以下结论:
MediaPlaybackService.java
public class MediaPlaybackService extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
private MediaSessionCompat.Callback mediaSessionCompatCallBack = new MediaSessionCompat.Callback()
{
@Override
public void onPlay() {
super.onPlay();
Toast.makeText(getApplication(),"Play Button is pressed!",Toast.LENGTH_SHORT).show();
}
@Override
public void onPause() {
super.onPause();
Toast.makeText(getApplication(),"Pause Button is pressed!",Toast.LENGTH_SHORT).show();
}
@Override
public void onSkipToNext() {
super.onSkipToNext();
Toast.makeText(getApplication(),"Next Button is pressed!",Toast.LENGTH_SHORT).show();
}
@Override
public void onSkipToPrevious() {
super.onSkipToPrevious();
Toast.makeText(getApplication(),"Previous Button is pressed!",Toast.LENGTH_SHORT).show();
}
@Override
public void onStop() {
super.onStop();
Toast.makeText(getApplication(),"Stop Button …
Run Code Online (Sandbox Code Playgroud) android keyevent media-player android-bluetooth android-mediasession
当从应用程序(android 和 ios)连接到自定义 BLE 设备时,我有两个选项
a) 首先在手机上配对设备(如耳机或其他设备),然后从应用程序中使用它来读取和写入数据
b) 无需在手机上配对,进入应用程序,搜索具有特定名称或地址的设备,然后连接到它并读取和写入数据。
什么时候一个人比另一个人更受青睐?只是当它需要在后台交互时还是我错过了什么?
bluetooth core-bluetooth bluetooth-lowenergy android-bluetooth
背景:
btsnoop hci 日志不再适用于 Android 上的较新版本。我必须使用错误报告来嗅探/窥探蓝牙流量:
在设备上:
在计算机上:
从航站楼:
$adb bugreport bugreport
$unzip bugreport.zip
$cd /FS/data/misc/bluetooth/logs/
$py3 btsnooz.py btsnoop_hci.log > btsnoop_hci.txt
使用Google或wireshark内置功能进行解释我猜测错误报告是使用设备上不同目录中保存的信息生成的。我的问题是蓝牙日志非常难以预测,我找不到任何有关其工作原理的有用文档。
问题:
即使我总是在启用蓝牙 HCI 监听 60 秒后禁用它,但 bugreport.zip 中的 /FS/data/misc/bluetooth/logs/ 的 5/10 倍没有 /bluetooth 文件夹,或者有时日志很短记录的时间少于 5 秒,但有时会超过 1000 秒或超过 1000 行。
问题:
设备上的蓝牙记录和错误报告生成具体何时开始?是在开发者选项中启用蓝牙 HCI 时,是在蓝牙打开或关闭时,还是在设备重新启动时?
我的应用程序执行以下操作:
onDescriptorWrite
它向 BT 设备发送命令。
一旦 BT 设备收到此命令,它就会开始向 Android 手机传输数据。
AndroidonCharacteristicChanged
正在捕获从 BT 设备发送的所有数据。
所有数据传输完毕后,Android 应用程序会将其写入文件。
我已经对其进行了测试,一切在三星(Android 11)、OnePlus(Android 11)和小米(Android 9)上运行得非常完美,但来自诺基亚(Android 11)的数据onCharacteristicChanged
被损坏。
此测试示例显示将传输的数据写入带有校验和的文件中。正如你所看到的,我在小米上得到了完全相同的字节,但在诺基亚上它有时会被损坏。
Tested on Xiaomi MiA1 (Android 9)
File_MD5: The right file MD5 -> AE36F08213B25B5E0EE19425257D0D85
File_MD5: Measurement file MD5: AE36F08213B25B5E0EE19425257D0D85 (ok)
File_MD5: Measurement file MD5: AE36F08213B25B5E0EE19425257D0D85 (ok)
File_MD5: Measurement file MD5: AE36F08213B25B5E0EE19425257D0D85 (ok)
File_MD5: Measurement file MD5: AE36F08213B25B5E0EE19425257D0D85 (ok)
File_MD5: Measurement file MD5: AE36F08213B25B5E0EE19425257D0D85 (ok)
File_MD5: Measurement file MD5: AE36F08213B25B5E0EE19425257D0D85 (ok) …
Run Code Online (Sandbox Code Playgroud) 我遇到一个问题,我可以连接到蓝牙设备一次,但断开连接后,在扫描蓝牙设备时我不再看到该设备。如果我完全关闭应用程序,设备仍然无法被发现,但如果我关闭手机,设备将再次被发现。
我还注意到这个问题发生在 Pixel、华为和 xiomi 设备上,但似乎适用于运行 Android 12 的三星。
我的假设是,Android 12 中有一些奇怪的功能,可以以某种方式保持连接与应用程序分开。在我的应用程序中,我调用此代码来断开连接:
gatt.close()
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以确保设备完全断开连接吗?
编辑: 打电话
bluetoothManager.getConnectedDevices(BluetoothProfile.GATT)
Run Code Online (Sandbox Code Playgroud)
断开连接并关闭后仍然返回我连接的设备。
EDIT2: 我可以使用以下代码重现此问题:
private var gatt: BluetoothGatt? = null
@SuppressLint("MissingPermission")
fun onDeviceClick(macAddress: String) {
logger.i(TAG, "onDeviceClick(macAddress=$macAddress)")
val bluetoothManager: BluetoothManager =
context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
if (gatt != null) {
logger.i(TAG, "Disconnecting")
gatt?.close()
gatt = null
printConnectedDevices(bluetoothManager)
return
}
printConnectedDevices(bluetoothManager)
val btDevice = bluetoothManager.adapter.getRemoteDevice(macAddress)
logger.d(TAG, "Device to connect: $btDevice")
gatt = btDevice.connectGatt(context, false, object : BluetoothGattCallback() {
override fun onConnectionStateChange(gatt: BluetoothGatt?, status: Int, newState: Int) { …
Run Code Online (Sandbox Code Playgroud) 我按照官方的例子来写这个程序
public class BluetoothActivity extends AppCompatActivity {
private static final long SCANNING_TIMEOUT = 5000; /* 5 seconds */
private static final int ENABLE_BT_REQUEST_ID = 1;
private BleWrapper mBleWrapper = null;
private boolean mScanning = false;
private Handler mHandler = new Handler();
private BluetoothAdapter mBluetoothAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bluetooth);
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
Toast.makeText(this, "no ble", Toast.LENGTH_SHORT).show();
finish();
}
final BluetoothManager bluetoothManager =
(BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = …
Run Code Online (Sandbox Code Playgroud) android ×7
bluetooth ×5
adb ×1
android-ble ×1
btsnoop ×1
google-pixel ×1
keyevent ×1
media-player ×1