hereと表示されているサービスに基づいて、Androidデバイスからサービスを購読しようとしていますが、要請の部分が機能しません。 7905F431-B5CE-4E99-A40F-4B1E122D00D0
を使用して広告を試みましたが、周辺機器がiPhoneのBluetoothデバイスリストに表示されません。また、(LE)スキャンとフィルタを使用して運がないANCSサーバーを検出します。何かヒント?AndroidでANCSを購読する
編集:コード
BleService.java
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic,
boolean enabled) {
Log.d(TAG, "setCharacteristicNotification");
if (mBluetoothAdapter == null || mBluetoothGatt == null) {
Log.w(TAG, "BluetoothAdapter not initialized");
return;
}
mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(UUID.fromString(SampleGattAttributes.DESCRIPTOR));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor)
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if (status == BluetoothGatt.GATT_SUCCESS) {
broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED);
}
}
SampleGattAttributes.java
public class SampleGattAttributes {
public static String ANCS_SERVICE = "7905F431-B5CE-4E99-A40F-4B1E122D00D0";
public static String NOTIFICATION_SOURCE = "9FBF120D-6301-42D9-8C58-25E699A21DBD";
public static String DATA_CONTROL = "22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB";
public static String DESCRIPTOR = "00002902-0000-1000-8000-00805f9b34fb";
}
MainActivity.java
private void displayServices(List<BluetoothGattService> services) {
for (BluetoothGattService service : services) {
if (service.getUuid().compareTo(UUID.fromString(ANCS_SERVICE)) == 0) {
for (BluetoothGattCharacteristic characteristic : service.getCharacteristics()) {
Log.d(TAG, "charac: " + characteristic.getUuid());
for (BluetoothGattDescriptor descriptor : characteristic.getDescriptors()) {
Log.d(TAG, "desc: " + descriptor.getUuid());
}
if (characteristic.getUuid().compareTo(UUID.fromString(NOTIFICATION_SOURCE)) == 0) {
bleService.setCharacteristicNotification(characteristic, true);
}
}
}
}
}
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (BleService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {
displayServices(bleService.getSupportedGattServices());
}
}
};
アップデート:私はiPhoneで宣伝されているサービスに接続した後で、サービスと特性を見つけることができます。ただし、通知を購読すると、iPhone上で通知を受け取るとonCharacteristicChanged
がトリガーされません。
update2:すべての書き込みdescriptor.setValue
コールは成功し、順番に実行されます。
Update3と:試験装置:this sample.
update4からコードの使用済み部分のNexus 5Xアンドロイド6.0.1。 iPhone 6S +のiOS 10.3.1
update5:私は最近、同様の問題に遭遇したBTログ
よくある質問Nexusデバイスの場合開発者のオプションには、「Bluetooth HCIスヌープログを有効にする」チェックボックスが1つあります。これを有効にすると、デバイスはBluetoothスタック上で起きているすべてのことをログに記録します....「HCIsnoop.log」というSdカードに保存されているログを参照してください。あなたのHD上にあなたのファイルを持っている場合、これらのBTログファイルを見るには、s/w(無料):http://www.fte.com/support/download.aspx?demo=ComProbe%20SD&type=capture&iid=1vをダウンロードしてください。これにより、あるデバイスから別のデバイスに(BTのWiresharkのように)交換されたパケットをすべて見ることができます。 – PN10
Githubにこのアプリケーションを投稿することはできますか?シンプルなANCS Androidクライアントは素晴らしいだろう – Jason