I am using the ACTION_REQUEST_ENABLE intent startActivityForResult (). Then it calls:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == imu.requestCode) {
if (resultCode == RESULT_OK) {
getPairedDevice();
initializeConnection();
}
}
}
initializeConnection () creates a new stream that initializes my input socket, creates another stream to handle Bluetooth input, and creates my output stream. Fragments of these features include:
myServerSocket = dev.createInsecureRfcommSocketToServiceRecord(uuid);
myBluetooth.cancelDiscovery();
myServerSocket.connect();
myBluetoothInputThread = new BluetoothInputThread(myServerSocket, handler); myBluetoothInputThread.setPriority(Thread.MAX_PRIORITY);
myBluetoothInputThread.start();
myBluetoothSocketOutputStream = myServerSocket.getOutputStream();
BluetoothInputThread extends the stream to create a separate input control process. This class communicates with its parent class through Handler.sendMessage
source
share