首先,我花了超过10个小时在Google上搜索解决方案......
我正在为运动员制作一个应用程序,做跑步或骑自行车等运动.它应该基于蓝牙LowEnergy.我有一个真正的心跳传感器设备,有问题.
问题是,如果我想测试扫描或其他东西,传感器并不总是有效.我的手机无法一直找到传感器,它只能在30次尝试中使用一次.所以我想问的是,有没有办法像心跳传感器一样模拟BLE传感器设备(例如通过PC)?
我有运行4.3及更高版本的设备(三星,LG和索尼智能手机),所以这应该不是问题.此外,我已经成功连接到BLE-Heartbeat传感器,但是为了测试它真的很难使用真正的传感器设备(因为我无法一直找到它的问题).
希望我的问题是可以理解的,有人可以帮助我!
android simulator sensor bluetooth-lowenergy android-bluetooth
我正在尝试使用蓝牙低功耗(BLE)通过Android应用程序连接到Arduino Uno.
我正在开发Android Studio,使用三星Galaxy S4进行测试,使用Android版本5.0.1
我按照以下链接开发:http
://www.truiton.com/2015/04/android-bluetooth-low-energy- ble-example /
我正在扫描设备,当我找到它时,我想在连接它之前得到它的UUID,以确保它是正确类型的设备:
mScanCallback = new ScanCallback() {
@Override
@TargetApi(21)
public void onScanResult(int callbackType, ScanResult result) {
BluetoothDevice btDevice = result.getDevice();
ParcelUuid[] uuids = btDevice.getUuids(); //<-- this is always null!! :(
Log.d(TAG, ""+btDevice.fetchUuidsWithSdp()); //<-- prints true.
Log.d(TAG, "result : " + result.toString()); //<-- prints a bunch of relevant info that contains the UUID I want to check.
Log.d(TAG, "uuids : " + uuids); //<-- prints null.
/*
for (ParcelUuid u : …Run Code Online (Sandbox Code Playgroud) uuid android bluetooth-lowenergy android-bluetooth arduino-uno
在试图读取Android API 18中蓝牙低功耗GATT特性的值时,我遇到了以下困境:检索存储在特征中的值的正确方法是什么?并且应该在哪个级别的堆栈中执行此操作?
在进行自己的研究时,我偶然发现了两种可能的方法:
BluetoothGattCharacteristic .getValue()
public void onClick(View v){
byteValue = mBTValueCharacteristic.getValue();
if ((byteValue[0] & 0x01) == 1)
byteValue[0] = 0x00;
else
byteValue[0] = 0x01;
mBTValueCharacteristic.setValue(byteValue);
mBTGatt.writeCharacteristic(mBTValueCharacteristic);
}
Run Code Online (Sandbox Code Playgroud)以上是引导我解决这个问题的原始代码.在其中,我尝试读取特征的值,并使用按钮简单地切换其状态.
bluetooth-lowenergy android-bluetooth android-4.3-jelly-bean
我需要使用具有语音识别功能的蓝牙耳机,这在S3,S4和Samsung Grand等设备上几乎可以正常使用.但是,当我在Nexus 7上尝试相同时,我得到了
BluetoothHeadsetServiceJni : Failed to start voice recognition, status: 6
Run Code Online (Sandbox Code Playgroud)
我在调用startVoiceRecognition()方法时出错.我正在使用此SO页面中的代码.
仅在某些设备中出现此问题的可能原因是什么?有什么方法可以解决这个问题吗?
嘿所有,
据我所知,Android的蓝牙堆栈(bluez)已在4.2上被取代.即使他们可能已经修复了许多以前的问题,但由于需要支持旧版本,我仍然需要与它们进行斗争.
如果有人事先处理过这个问题并且可以解释一些问题,我将非常感激.
蓝牙应用程序连接到我们自己的自定义SPP设备(我们使用标准UUID).它使用蓝牙服务,运行在它自己的进程上.这个应用程序要求运行蓝牙工作几个小时.
在省电/屏幕锁定期间,应用程序在数据通过蓝牙无线电进入时保持活动状态,并且我还定期检查设置的警报,我请求CPU时间重新连接并继续工作(如果需要)
现在; 该系统工作正常的大部分时间,但是,在某些罕见的情况下,当屏幕被锁定,并在省电模式下,对于原因,我不明白,在写入到输出流(蓝牙接口),一切似乎都在没有检测到断开连接的情况下通过.spp设备仍然声明连接和配对有效但没有收到任何信息.
在Android方面,日志显示对BluetoothSocket.cpp :: writeNative的本机调用(假设它与bluez蓝牙堆栈直接相关),似乎只是将字节正确地写入蓝牙无线电而不报告任何类型的错误.
写入输出流的代码段:
public void write(byte[] bytes) {
try {
Log.d(LOGGER.TAG_BLUETOOTH," bluetooth bytes to write : "+bytes);
mmOutStream.write(bytes);
mmOutStream.flush();
Log.d(LOGGER.TAG_BLUETOOTH," bluetooth bytes written : "+bytes);
} catch (IOException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
logcat:
D/com.our.app.bluetooth(8711):发送字节:[B @ 41e0bcf8
D/com.our.app.bluetooth(8711):要写的蓝牙字节:[B @ …
TLDR:服务发现结果discoverServices()是否会因底层传输(LE与BR/EDR)而有所不同?
我有一个混合模式蓝牙配件,提供蓝牙经典设备和蓝牙LE外设的独特功能.
Android无法发现配件的蓝牙LE GATT服务,除非您使用隐藏的peerBluetoothDevice.connectGatt(context, autoConnect, gattCallback, BluetoothDevice.TRANSPORT_LE)API允许您强制使用其中任何一个TRANSPORT_LE或TRANSPORT_BREDR.
当我通过设备连接peerBluetoothDevice.connectGatt(context, autoConnect, gattCallback)然后调用时,discoverServices()我只发现通用的服务UUID(并且只有在许多连接尝试失败后才会发送神秘状态133 onConnectionStateChange).
但是,当我调用隐藏peerBluetoothDevice.connectGatt(context, autoConnect, gattCallback, BluetoothDevice.TRANSPORT_LE)然后调用时,discoverServices()我得到完整的预期服务发现响应:
这是预期的Android框架行为(怀疑它,因此隐藏API)?用这种"混合模式"操作设计外围设备是不好的形式?
我正在使用android BLE(蓝牙低功耗).我在使用startLeScan(UUID[] serviceUuids, BluetoothAdapter.LeScanCallback callback)方法扫描BLE设备时遇到了麻烦,
但startLeScan(BluetoothAdapter.LeScanCallback callback) 工作正常.
当我使用过滤器扫描特定的serviceUUID时,回调没有执行.我正在测试三星galaxy s6.
我想知道这个问题是特定于设备还是扫描函数中存在一些错误.
我正在开发一个应用程序,该应用程序将检测蓝牙信号(Sensoro 智能信标设备)并打开活动。但我希望应用程序仍然能够检测到信号,即使应用程序处于后台甚至被杀死。我使用了前台服务,当我打开应用程序并在活动之间移动时,它会检测到信号,但是当将应用程序发送到后台并打开其他应用程序时,侦听器会停止,尽管服务仍在工作。我正在打印日志。System.out.println("Sensoro 2" );即使我终止应用程序或打开另一个应用程序,也会继续打印。但是 BeaconManagerListener 中的打印日志不起作用。我尝试使用后台服务,但它也不起作用。您能否告知,当应用程序在后台或被杀死时,是否有一种方法可以使侦听器在服务中工作?这是服务代码:
public class MyService extends Service {
public static final String CHANNEL_ID = "ForegroundServiceChannel";
int service_timer=0;
Timer timer = new Timer();
SensoroManager sensoroManager;
@Override
public void onCreate() {
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
sensoroManager = SensoroManager.getInstance(MyService.this);
String input = intent.getStringExtra("inputExtra");
System.out.println("Sensoro 2" );
createNotificationChannel();
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,
0, notificationIntent, 0);
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Foreground Service")
.setContentText(input) …Run Code Online (Sandbox Code Playgroud) 我能够配对蓝牙键盘但无法连接以使其成为输入设备.我浏览了开发者网站提供的文档 - http://developer.android.com/guide/topics/connectivity/bluetooth.html#Profiles
它表示Android蓝牙API提供以下蓝牙配置文件的实现,但您可以实现接口BluetoothProfile编写自己的类以支持特定的蓝牙配置文件.
没有关于如何为HID蓝牙设备(键盘)实现BluetoothProfile的文档
Android本身已经为HID设备实现了蓝牙连接,但这些API是隐藏的.我也试过反思来使用它们.我没有得到任何错误,但键盘没有作为输入设备连接.这就是我所做的 -
private void connect(final BluetoothDevice bluetoothDevice) {
if(bluetoothDevice.getBluetoothClass().getDeviceClass() == 1344){
final BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothProfile.ServiceListener mProfileListener = new BluetoothProfile.ServiceListener() {
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
Log.i("btclass", profile + "");
if (profile == getInputDeviceHiddenConstant()) {
Class instance = null;
try {
//instance = Class.forName("android.bluetooth.IBluetoothInputDevice");
instance = Class.forName("android.bluetooth.BluetoothInputDevice");
Method connect = instance.getDeclaredMethod("connect", BluetoothDevice.class);
Object value = connect.invoke(proxy, bluetoothDevice);
Log.e("btclass", value.toString());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InvocationTargetException …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中我有启动和停止按钮,当用户按下启动时我调用startScan方法
bluetoothAdapter.getBluetoothLeScanner().startScan(getLeScanCallback());
Run Code Online (Sandbox Code Playgroud)
当用户按下停止时,我会调用stopScan,但它似乎什么也没做.BluetoothAdapter会持续扫描新设备.
bluetoothAdapter.getBluetoothLeScanner().stopScan(getLeScanCallback());
Run Code Online (Sandbox Code Playgroud)
这是我的getLeScanCallback方法:
private ScanCallback getLeScanCallback(){
ScanCallback leScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
super.onScanResult(callbackType, result);
boolean duplicate = false;
for(Device d : devices) {
if(d.getAddress().equals(result.getDevice().getAddress()))
duplicate = true;
}
if(!duplicate) {
Device device = new Device();
device.setName(result.getDevice().getName());
device.setAddress(result.getDevice().getAddress());
device.setStatus(getString(R.string.disconnected));
devices.add(device);
deviceListAdapter.notifyDataSetChanged();
}
}
@Override
public void onBatchScanResults(List<ScanResult> results) {
super.onBatchScanResults(results);
}
@Override
public void onScanFailed(int errorCode) {
super.onScanFailed(errorCode);
}
};
return leScanCallback;
}
Run Code Online (Sandbox Code Playgroud)
即使在调用stopScan()之后它也会被调用.我做错了什么,换句话说,如何停止扫描BLE设备?