运行下面的代码,我的 Galaxy 平板电脑 (SCH-I905 - Android 4.0.4) 正确地发现了 PC 上的三个蓝牙服务。在 Galaxy Nexus - Android 4.2.2 上运行相同的代码只能找到其中一项服务。任何想法表示赞赏:
private final BroadcastReceiver ServiceReceiver = new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if ( BluetoothDevice.ACTION_UUID.equals(action) )
{
BluetoothDevice device = intent.getParcelableExtra("android.bluetooth.device.extra.DEVICE");
Parcelable[] uuidExtra = intent.getParcelableArrayExtra("android.bluetooth.device.extra.UUID");
for( int i = 0; i < uuidExtra.length; i++ )
{
Toast.makeText( this, device.getName() + ": " + uuidExtra[i].toString(), Toast.LENGTH_LONG).show();
}
}
}
};
在 Eclipse 调试器中,以下数组显示了三个事件 [00001000-0000-1000-8000-00805f9b34fb、00001115-0000-1000-8000-00805f9b34fb、00001202-0000-1000-8000-1000-1000-8000-015805f90030b,但仅适用于平板电脑 [00001115-0000-1000-8000-00805f9b34fb -0000-1000-8000-00805f9b34fb] 用于 Nexus。不知道是版本问题还是硬件问题。谢谢你,约翰
最后一点 - 我正在使用... BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); device.fetchUuidsWithSdp();