我需要获取CONNECTED设备的名称和地址。
这是我到目前为止已经尝试过的方法,通过它我可以获取配对的设备列表和地址。
public class MainActivity extends AppCompatActivity {
TextView mBlue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mBlue = (TextView) findViewById(R.id.Bluetooth);
String s = " ";
BluetoothAdapter ba = BluetoothAdapter.getDefaultAdapter();
Set <BluetoothDevice> devices = ba.getBondedDevices();
if (ba != null) {
for (BluetoothDevice device: devices)
s += device.getName() + "-" + device.getAddress() + "\n";
} else
s += "No address";
mBlue.setText(s.toString());
}
}
如何获取连接的蓝牙设备的设备地址/名称?
请帮助我提供清晰的代码(清单代码和类代码)。我看过SO上的其他帖子,但我听不清。请帮助解决此问题。