我不明白蓝牙UUID是什么意思.UUID是否表示协议(例如RFCOMM)?如果是这样,为什么这些createRfcommSocketToServiceRecord()方法需要UUID,当他们在名字中指定rfcomm时?为什么BluetoothChat示例代码有一个看似随意的,硬编码的UUID?
我的问题出现了,因为,根据这个问题,当运行4.0.4的设备尝试使用反射连接(到外部的,非Android设备)时,我得到一个空指针异常.但是,该问题的解决方案对我不起作用.UUID muuid = device.getUuids()[0].getUuid();提出异常.
编辑:我已经通过根据此答案(使用UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");)硬编码串行端口服务的UUID解决了这个问题.
我更加困惑的是为什么我需要提供一个UUID来创建一个不安全的rfcomm套接字,createInsecureRfcommSocketToServiceRecord(),但不使用反射方法.
任何人都可以理顺我吗?
我有兴趣通过蓝牙连接到基于iOS的设备.我可以看到"本地网络"服务已公开,但我找不到任何有关它的额外信息.存储在密钥0x0204下的属性看起来像Bonjour密钥.
使用哪种协议?如何使用Linux,Mac或配备蓝牙芯片的自带嵌入式设备与iOS设备通信?
这是在OS X下使用蓝牙资源管理器提取的SDP数据,而iOS设备运行Gameloft的Star Battalion.
{
0x0000 = uint32(1330188565),
0x0200 = uint32(2),
0x0202 = string(004wD7l1A..0|0|0|ivucic-À'),
0x030a = uint32(0),
0x0009 = { { uuid16(11 15), uint16(256) } },
0x0201 = string(_657o30a6rmst07À),
0x0005 = { uuid16(10 02) },
0x0100 = string(Local Network),
0x0001 = { uuid16(11 15) },
0x0203 = string(004wd7l1a..0|0|0|ivucic-_657o30a6rmst07À
0xf000 = uint8(2),
0x0204 = string( txtvers=1state=A),
0x0008 = uint8(255),
0x0006 = { uint16(25966), uint16(106), uint16(256), uint16(26226), uint16(106), uint16(272), uint16(25701), uint16(106), uint16(288), uint16(27233), uint16(106), uint16(304) },
0x0004 = { { uuid16(01 …Run Code Online (Sandbox Code Playgroud) 用于测试的设备:Nexus 4,Android 4.3
连接工作正常,但onCharacteristicChanged我的回调方法永远不会被调用.但是我正在使用setCharacteristicNotification(char, true)inside 注册通知onServicesDiscovered,该函数甚至返回true.
设备日志(当通知应该出现/通过蓝牙设备发送时,实际上根本没有消息):
07-28 18:15:06.936 16777-16809/de.ffuf.leica.sketch D/BluetoothGatt: setCharacteristicNotification() - uuid: 3ab10101-f831-4395-b29d-570977d5bf94 enable: true
07-28 18:15:06.936 4372-7645/com.android.bluetooth D/BtGatt.GattService: registerForNotification() - address=C9:79:25:34:19:6C enable: true
07-28 18:15:06.936 4372-7645/com.android.bluetooth D/BtGatt.btif: btif_gattc_reg_for_notification
07-28 18:15:06.946 4372-7645/com.android.bluetooth D/BtGatt.btif: btgattc_handle_event: Event 1018
07-28 18:15:06.946 4372-7645/com.android.bluetooth D/BtGatt.GattService: onRegisterForNotifications() - address=null, status=0, registered=1, charUuid=3ab10101-f831-4395-b29d-570977d5bf94
07-28 18:15:06.946 4372-7645/com.android.bluetooth D/BtGatt.btif: btgattc_handle_event: Event 1016
07-28 18:15:06.946 4372-7645/com.android.bluetooth D/BtGatt.btif: btgattc_handle_event: Event 1018
07-28 18:15:06.946 4372-7645/com.android.bluetooth D/BtGatt.GattService: onRegisterForNotifications() - address=null, status=0, …Run Code Online (Sandbox Code Playgroud) android bluetooth bluetooth-lowenergy gatt android-4.3-jelly-bean
是否可以将iOS 7设备作为蓝牙LE外设(iBeacon)运行并在后台进行广告宣传?我已经能够使用下面的代码在前台做广告,并且可以从另一个iOS设备看到它但是一旦我回到主屏幕就停止广告.我确实在plist中添加了蓝牙外设背景模式,但这似乎没有帮助,虽然我得到提示说该设备想要在后台使用蓝牙.我做错了什么,或者这在iOS 7中是不可能的?
peripManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral
{
if (peripheral.state != CBPeripheralManagerStatePoweredOn) {
return;
}
NSString *identifier = @"MyBeacon";
//Construct the region
CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:identifier];
//Passing nil will use the device default power
NSDictionary *payload = [beaconRegion peripheralDataWithMeasuredPower:nil];
//Start advertising
[peripManager startAdvertising:payload];
}
Run Code Online (Sandbox Code Playgroud)
这是接收/收听端的代码:
- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons
inRegion:(CLBeaconRegion *)region
{
//Check if we have moved closer or farther away from the iBeacon…
if (beacons.count > 0) {
CLBeacon *beacon …Run Code Online (Sandbox Code Playgroud) 我最近买了通过蓝牙与Android手机/平板电脑连接的中文设备.由于没有适用于windows/linux的应用程序,我想创建一个供个人使用的应用程序.
通常手机连接到设备并交换一些数据.我将PC连接到设备并查看串行调试器并进行管理以发现协议(仅限一种方式).电话仅向设备发送一个命令.但是这次我无法找出它包含的内容.
有没有软件可以让我查看通过蓝牙发送的数据?我试过反编译应用程序,但它看起来真的很不友好.
谢谢.
我想检查是否定期在任何Android设备上启用蓝牙.有没有使用BroadcastReceiver可以捕获的意图,还是有其他方法可以做到这一点?
我有一个带有按钮的应用程序,用于打开和关闭BT.我在那里有以下代码;
public void buttonFlip(View view) {
flipBT();
buttonText(view);
}
public void buttonText(View view) {
Button buttonText = (Button) findViewById(R.id.button1);
if (mBluetoothAdapter.isEnabled() || (mBluetoothAdapter.a)) {
buttonText.setText(R.string.bluetooth_on);
} else {
buttonText.setText(R.string.bluetooth_off);
}
}
private void flipBT() {
if (mBluetoothAdapter.isEnabled()) {
mBluetoothAdapter.disable();
} else {
mBluetoothAdapter.enable();
}
}
Run Code Online (Sandbox Code Playgroud)
我正在调用按钮Flip,它会翻转BT状态,然后调用ButtonText,它应该更新UI.但是,我遇到的问题是,BT打开需要几秒钟 - 在这几秒钟内,BT状态未启用,使我的按钮说蓝牙关闭,即使它将在2秒内打开.
我STATE_CONNECTING在BluetoothAdapter android文档中找到了常量,但是......我根本就不知道如何使用它,成为一个新手和所有.
所以,我有两个问题:
我一直在阅读如何使用GameKit通过蓝牙在iOS设备之间传输数据.我本身并不是在编写游戏,但确实需要在两个设备之间传输少量二进制数据.在两个iOS设备之间,这很容易.但是,我想知道是否可以通过相同的机制在iOS设备和Android设备之间传输数据.
有没有人遇到过可以解释如何执行此操作的文档/教程?它在技术上是否可行?或者苹果公司是否提出了某种限制措施来防止这种情况发生?
我发现的另一个选择是Bonjour通过蓝牙.对于这种类型的操作,这是一个更合适的选择吗?
我想通过蓝牙连接3个设备(My Droid必须连接到2个蓝牙设备).我已经使用蓝牙聊天将我的Droid连接到1个设备我应该如何为多个蓝牙设备修改它?请问你能帮帮我吗?
使用CoreBluetooth我想将数据从iPhone发送到Mac.为此,我编写了像iPhone一样的代码作为'Peripheral'和Mac作为'Central'.
它工作得很好,但有时会直接断开连接,然后连续连接和断开连接.
有时当它试图重新连接时,在中心它直接调用'didDisconnectPeripheral'委托方法.但有时它在'didUpdateNotificationStateForCharacteristic'中有错误"句柄无效".
我在网上提到了所有的链接.但我无法解决这个问题.我在iPhone中认为它存储了蓝牙缓存.
请提出解决方法如何解决"句柄无效"错误?
以下是一些重要的方法.
对于Peripheral,我写了如下代码.
在Appdelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.peripheral = [[PeripheralServerObject alloc] init];
self.peripheral.serviceUUID = [CBUUID UUIDWithString:@"4w24"];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
在外围对象文件中:
//To Check Bluetooth State
- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral {
switch (peripheral.state) {
case CBPeripheralManagerStatePoweredOn:
[self enableService];
break;
case CBPeripheralManagerStatePoweredOff: {
[self disableService];
break;
}
}
// To Add characteristics to Service
- (void)enableService
{
[self.peripheral removeAllServices];
self.service = [[CBMutableService alloc]
initWithType:self.serviceUUID primary:YES];
self.authChar =
[[CBMutableCharacteristic alloc] initWithType:[CBUUID UUIDWithString:@"a86e"]
properties:CBCharacteristicPropertyNotify
value:nil
permissions:CBAttributePermissionsReadable];
self.respChar =
[[CBMutableCharacteristic …Run Code Online (Sandbox Code Playgroud)