I am in an Android project which uses Bluetooth sockets. The app is the client socket. But the app crashes when working. Can anyone help me in solving the issue.
here is the code
public class READ extends AppCompatActivity {
private static String btAdress = "00:10:60:D1:95:CD";
BluetoothSocket mmSocket;
BluetoothDevice mmDevice;
BluetoothAdapter btAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_read);
}
public void ConnectThread(View v){
BluetoothDevice device;
device = btAdapter.getRemoteDevice(btAdress);
ConnectT(device);
}
public void ConnectT(BluetoothDevice device) {
// Use a temporary object that is later assigned to mmSocket,
// because mmSocket is final
mmDevice = device;
BluetoothSocket tmp = null;
String uuid = "a60f35f0-b93a-11de-8a39-08002009c666";
// Get a BluetoothSocket to connect with the given BluetoothDevice
try {
// MY_UUID is the app's UUID string, also used by the server code
tmp = device.createRfcommSocketToServiceRecord(UUID.fromString(uuid));
} catch (IOException e) { }
mmSocket = tmp;
try {
// Connect the device through the socket. This will block
// until it succeeds or throws an exception
mmSocket.connect();
} catch (IOException nullException) {
// Unable to connect; close the socket and get out
try {
mmSocket.close();
} catch (IOException closeException) { }
}
}
}
Thanks in Advance.