2016-12-05 58 views
0

如何在与应用程序配对时过滤蓝牙标签。例如,“平铺”不会与其授权标签以外的标签连接。我的问题是,他们如何通过应用程序识别他们的授权标签?如何通过Android应用程序过滤蓝牙标签

+0

你的意思是 '设备名称'? –

+0

详细说明,如果我的蓝牙范围内有很多标签,我只想在应用中显示我公司的标签。其他标签不会显示在应用程序中。 –

回答

1

一个简单的解决方案是连接到一个不受信任的设备,发送一个预期具体结果的信号,如果它收到罚款,然后“信任”该设备。

然后,在下一次的负荷,检查配对的MAC地址..

一种近乎:

private BluetoothDevice mDevice = null; 
if (mDevice == null) { 
     BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
     if (mBluetoothAdapter != null) { 
      if (mBluetoothAdapter.isEnabled()) { 
       Set<BluetoothDevice> bluetoothDevices = mBluetoothAdapter 
         .getBondedDevices(); 
       if (bluetoothDevices != null && bluetoothDevices.size() > 0) { 
        String bondedID = SharedPreferences.getInstance(
          getApplicationContext() 
        ).getPairedAddress(); 
        if (bondedID != null) { 
         for (final BluetoothDevice device : bluetoothDevices) { 
          if (device != null 
            && device.getAddress().equals(bondedID)) { 
           mDevice = device; 
           break; 
          } 
         } 
        } 
       } else { 
        Logger.v(TAG, "There are no Bluetooth Paired devices"); 
       } 
      } 
     } 
    } 
+0

你的意思是发送一个信号到蓝牙标签,作为回应,如果应用程序收到预期的结果,然后相信标签? –

+0

是的,它可以工作(这和我一样),但其他方式也很常见,比如只信任特定的设备名称(使用'mDevice.getName()')等。 – Bonatti

+0

我的想法与安全问题有关。如果有人使用我的应用销售自己的标签,我将如何防止我的应用信任这些标签。 –