2016-09-24 4 views
4

BLE通信のカスタムプロトコルを構築しました。 このプロトコルでは、デバイス名をスマートフォンとビーコンの間の通信における識別価値として使用し、データペイロードとしてUUIDを使用します。システムに触れることなくカスタムBTアダプタ名でBLE広告を公開

だから私は持っている私のコードで:

BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
//Needed for let the protocol work 
bluetoothAdapter.setName("CUSTOMAA"); 

//Get Advertiser 
BluetoothLeAdvertiser bluetoothLeAdvertiser = bluetoothAdapter.getBluetoothLeAdvertiser(); 

//Configure advertiser 
AdvertiseSettings settings = new AdvertiseSettings.Builder() 
         .setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED) 
         .setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM) 
         .setConnectable(true) 
         .build(); 

//Uuid is another important part of our protocol 
AdvertiseData advertiseData = new AdvertiseData.Builder() 
           .setIncludeDeviceName(true) 
           .addServiceUuid(getUuid()) 
           .build(); 

//Start Advertising 
bluetoothLeAdvertiser.startAdvertising(settings, advertiseData, advertiseCallback); 

それは私が他のデバイスとスマートフォンのBluetoothを検索する場合、表示される名前は「CUSTOMAA」でなく、アプリケーションがオンのとき、正常に動作しますが、 Bluetoothの設定ページ(例:「Marco's Android」)に設定したもの。 私は、アプリケーションを閉じてからBluetoothの電源を切るか、電話を再起動すると元の名前に戻りました。

他の通信(例えば、システムBluetoothAdapterの「コピー」を広告のみに使用する)のためにオリジナルのデバイス名に触れずに、カスタムデバイス名で広告データを送信する方法はありますか?私はこの行を追加する方法buildAdvertiseData()

、クラスAdvertiserService.javahttps://developer.android.com/samples/BluetoothAdvertisements/index.html

::私は同じ問題に遭遇した

答えて

1

は、ここに私の考えは

である私は、ここから、このサンプルプロジェクトを使用

dataBuilder.addServiceData(Constants.Service_UUID,"my_device_name".getBytes()); 

これはservice_UUIDでブロードキャストされます と私は私が私のget service_UUIDデータ

ScanResult.getScanRecord().getServiceData().get(Constants.Service_UUID) 

とScanResultを得ることができます 方法onScanResult

ScannerFragment.java内部bytes[]


と内部クラスSampleScanCallbackにservice_UUIDデータ "my_device_name" を追加溶液

希望するhエルプ

関連する問題