要获取Android蓝牙信标的唯一标识符,可以使用BluetoothAdapter类的getAddress()方法。下面是一个示例代码:
import android.bluetooth.BluetoothAdapter;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 获取蓝牙适配器
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// 检查设备是否支持蓝牙
if (bluetoothAdapter == null) {
// 设备不支持蓝牙
return;
}
// 获取蓝牙信标的唯一标识符
String bluetoothAddress = bluetoothAdapter.getAddress();
// 打印蓝牙信标的唯一标识符
System.out.println("Bluetooth address: " + bluetoothAddress);
}
}
请注意,getAddress()方法返回的是蓝牙适配器的MAC地址,而不是蓝牙信标的唯一标识符。在大多数情况下,设备的MAC地址可以用作唯一标识符。