我找到了用于管理服务连接的示例代码。但我不知道如何使用它。在Android服务上连接蓝牙
我只写在这里,我不明白的代码,看到所有的代码:
CODE
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("popopo", "Onstart Command");
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter != null) {
device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
deviceName = device.getName();
String macAddress = device.getAddress();
if (macAddress != null && macAddress.length() > 0) {
connectToDevice(macAddress);
} else {
stopSelf();
return 0;
}
}
String stopservice = intent.getStringExtra("stopservice");
if (stopservice != null && stopservice.length() > 0) {
stop();
}
return START_STICKY;
}
我连接正确地将没有服务蓝牙,使用此代码获取设备:
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
// Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
// Add the name and address to an array adapter to show in a ListView
mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
我的问题是:当onStartCommand()要执行时如何通过我发现的蓝牙设备ID?
当我没有执行ACTION_FOUND时,它试图连接哪个蓝牙设备?
2016-04-28
Jose M.