I found a sample code for manage connection on service. But I don't know how use it.
I only write here the code that I don't understand, to see all the code:
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;
}
I connect correcly to bluetooth without service, getting device with this code:
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());
}
My question is: How to pass my found Bluetooth device ID when onStartCommand()
gonna executed?
Which Bluetooth Device it's trying to connect when I don't executed ACTION_FOUND?