我正在尝试制作一个应用程序,我可以将我的电话从Android手机(SOURCE)转移到音频开发套件(CSR 8670开发套件作为SINK).我能够通过A2dp配置文件传输音频,但转移呼叫我需要启用我仍然面临问题的HFP.是否有通过蓝牙免提配置文件或A2dp配置文件转移呼叫的正确方法?
有点卡在这里,可能需要你的帮助.我想一次阅读几个BLE特征,有些人建议使用PriorityQueue.我已经知道所有的uuids等,只需要一种方法一次读几个.任何人都可以解释它究竟应该是什么样的?或者还有另一个更简单的解决方案?
在此先感谢,这是我的代码:
public static final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
PriorityQueue<BluetoothGattCharacteristic> queue = new PriorityQueue<BluetoothGattCharacteristic>();
// When connection state changes
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
Log.v(TAG, "Connected!");
gatt.discoverServices();
}
if (newState == BluetoothProfile.STATE_DISCONNECTED) {
Log.v(TAG, "Disconnected...");
}
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
List<BluetoothGattService> services = gatt.getServices();
BluetoothGattService rightService = null;
for (int i = 0; i < services.size(); i++) {
if (services.get(i).getCharacteristics().size() > 8) { …Run Code Online (Sandbox Code Playgroud) java android priority-queue bluetooth-lowenergy android-bluetooth
无论是蓝牙耳机还是手机?
如何在Android代码中区分蓝牙耳机和支持蓝牙的Android设备.
我正在开发一个小应用程序,因为我有通过蓝牙阻止数据传输的功能,但它需要允许通过蓝牙耳机进行通信.
我提到了示例和代码,因为他们建议我只配对/取消配对蓝牙设备. Android:如何以编程方式配对蓝牙设备?
or else
Run Code Online (Sandbox Code Playgroud)获取所有连接的设备. 在Android中,如何获取连接的蓝牙设备的配置文件?
是否可以在与设备连接类型相关的设备中获取任何广播消息?
请帮我解决这个问题,将连接的蓝牙设备区分为耳机/安卓设备(手机)等.,
先感谢您.
我有Android应用程序暴露BLE服务器.我连接BluetoothGattServer#connect.它有效 - 我的应用程序通过STATE_CONNECTED调用BluetoothGattServerCallback#onConnectionStateChange.当我完成客户端后,我尝试使用BluetoothGattServer#cancelConnection与我的应用程序断开连接.
但我没有接到对BluetoothGattServerCallback#onConnectionStateChange的调用,似乎连接仍然处于活动状态,因为我的BLE客户端没有开始做广告(当没有任何连接时它就会这样做).
在logcat中我只看到:
BluetoothGattServer: cancelConnection() - device: XX:XX:XX:XX:XX:XX
Run Code Online (Sandbox Code Playgroud)
有趣的是,我的应用程序在完全关闭BT后立即调用BluetoothGattServerCallback#onConnectionStateChange和STATE_DISCONNECTED.
android bluetooth-lowenergy android-bluetooth gatt android-ble
我有一个android.speech.tts.TextToSpeech.speak()用于读取消息的应用程序.
这些消息只能读出连接的蓝牙耳机.所以在我调用说话方法之前,我会检查AudioManager.isBluetoothA2dpOn();
说话方法实施:
ttsOptions.putInt(TextToSpeech.Engine.KEY_PARAM_STREAM, AudioManager.STREAM_VOICE_CALL);
ttsOptions.putFloat(TextToSpeech.Engine.KEY_PARAM_VOLUME, 1.0f);//MAX
tts.speak(text, TextToSpeech.QUEUE_ADD, ttsOptions, utteranceID);
Run Code Online (Sandbox Code Playgroud)
这种行为按预期工作了大约一年,但最近它在三星设备上失败的方式只是它将音频路由到手机的扬声器并且消息被大声读出.
我设法通过以下方式解决了路由问题:
1.AudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
2.mAudioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN);
3.mAudioManager.startBluetoothSco();
4.播放简短的音频文件
如果我执行这4个步骤,音频路由将被修复并路由到蓝牙耳机.
问题:
为什么三星设备将音频路由到手机扬声器而不是蓝牙设备?
任何可靠的方法来检查音频是否将被路由到耳机而不是AudioManager.isBluetoothA2dpOn();?
android text-to-speech android-audiomanager audio-route android-bluetooth
我们即将发布我们软件的新版本,对于之后的版本,我们的目标是使我们的蓝牙SPP连接的连接过程更加可靠.我们在产品中使用RN42模块,目前有时可能需要多次尝试才能连接到我们的主板.
这是我目前的代码:
class ConnectThread extends Thread {
BluetoothDevice mDevice;
public ConnectThread(BluetoothDevice device) throws SecurityException, NoSuchMethodException {
mDevice = device;
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
try {
btSocket = mDevice.createInsecureRfcommSocketToServiceRecord(uuid);
} catch (IOException e) {
Log.e("Error", "Could not create socket!");
}
}
public void cancel() {
interrupt();
try {
Log.i("Treadmill", "in connect thread cancellation");
btSocket.close();
} catch (IOException localIOException) {
Log.e("Treadmill", "exception + " + localIOException.getMessage());
}
}
public void run() {
btAdapter.cancelDiscovery();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Log.e("whatever", …Run Code Online (Sandbox Code Playgroud) 我试图通过广播接收器捕获与 android 的配对过程中的事件。看起来,这BluetoothDevice.BOND_BONDING是可行的,但BluetoothDevice.BOND_BONDED不是。
在旧的 Android 版本中,此方法有效(尝试过 Android 6 和 7),但在较新的 Android 版本中(尝试过 Android 9,多种设备),此方法不起作用。为了重现这个问题,我做了一个简单的程序:
Java文件:
package com.example.bluetoothtest;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
BroadcastReceiver receiver;
BluetoothDevice mDevice;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action)){
mDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (mDevice.getBondState() == …Run Code Online (Sandbox Code Playgroud) 当一个 iOS BLE 外围设备进入后台状态时,广告数据包不会以常规方式发出,它们被放置在一个特殊的“溢出”区域,只有另一个 iOS 设备明确寻找该设备才能检测到该区域。
也就是说,您应该知道,当您的应用程序在后台时,广告的运作方式与您的应用程序在前台时的运作方式不同。特别是,当您的应用在后台投放广告时:
• CBAdvertisementDataLocalNameKey 广告键被忽略,并且外围设备的本地名称不被广告。
• 包含在CBAdvertisementDataServiceUUIDsKey 广告键值中的所有服务UUID 都放置在一个特殊的“溢出”区域中;它们只能被明确扫描它们的 iOS 设备发现。
Android 中心(扫描仪)有什么方法可以检测任何广告的自定义 UUID,而无需连接到 iOS 外围设备?
ios core-bluetooth bluetooth-lowenergy android-bluetooth ios-bluetooth
我目前正在测试 Android配套设备配对,但我不确定如何从REQUEST_COMPANION_RUN_IN_BACKGROUND权限中受益。
在 Google 文档的一部分中说:
设备配对后,设备可以利用 REQUEST_COMPANION_RUN_IN_BACKGROUND 和 REQUEST_COMPANION_USE_DATA_IN_BACKGROUND 权限从后台启动应用程序。例如,您可以使用这种配对设备的方法对支持 BLE 的智能手表进行初始配置。
在许可本身中:
允许配套应用在后台运行。
在CompanionDeviceManager文档中,它说:
如果您的应用需要从电池优化中排除(在后台运行)或具有不受限制的数据访问(在后台使用数据),您可以分别声明您使用 android.Manifest.permission#REQUEST_COMPANION_RUN_IN_BACKGROUND 和。
有人可以解释(或指向一些示例代码)如何利用此权限在后台运行应用程序?理想情况下,我想从配对的蓝牙 LE 外围设备触发配套应用程序中的操作。
android bluetooth-lowenergy android-bluetooth android-ble wear-os
我正在开发一个使用蓝牙的 Android 应用程序,我想使用新的 Android 12 Bluetooth_SCAN 和 CONNECT 权限来消除对位置权限的需要
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
如蓝牙文档所示
问题是,该应用程序有一项主要功能和一项可选功能。主要功能在这些权限下运行良好。
然而,可选功能使用信标扫描。当使用“neverForLocation”标志时,Android 操作系统会从扫描中过滤掉这些信标。
注意:如果您在 android:usesPermissionFlags 中包含 neverForLocation,则会从扫描结果中过滤掉一些 BLE 信标。
如果从清单权限中删除了该标志,则在扫描期间会出现信标。
但是,如果我从清单中删除此标志,那么即使不想使用此功能的用户也必须提供位置权限,否则正常的 BLEScan 不会返回任何内容。这是我想避免提供的事实,即这些新权限的全部原因是避免询问用户位置。
有没有办法在向操作系统发出实际运行时请求权限时提供此标志,而不是在清单中声明它?任何帮助或想法表示赞赏。
android ×9
android-ble ×2
bluetooth ×2
android-12 ×1
audio-route ×1
gatt ×1
ios ×1
iot ×1
java ×1
rfcomm ×1
spp ×1
wear-os ×1