2016-12-05 55 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

我的想法與安全問題有關。如果有人使用我的應用銷售自己的標籤,我將如何防止我的應用信任這些標籤。 –