unfortunately, I have some problems with android\'s bluetooth. For my test environment I use a Nexus 4 with Android 4.4.2.
I have a Java Application on my PC, which
My fix for the question i have asked:
private synchronized void clearFileDescriptor(){
try{
Field field = BluetoothSocket.class.getDeclaredField("mPfd");
field.setAccessible(true);
ParcelFileDescriptor mPfd = (ParcelFileDescriptor)field.get(socket);
if(null == mPfd){
return;
}
mPfd.close();
}catch(Exception e){
Log.w(SensorTicker.TAG, "ParcelFileDescriptor could not be cleanly closed.");
}
}
So above is the method i have written to close the filedescriptor, and the below when i have used this code: Whenever, socket has to be close:
private synchronized void cleanClose() {
if (socket != null) {
try {
clearFileDescriptor();
//clearLocalSocket();
socket.close();
}
catch (IOException e) {
Log.w(SensorTicker.TAG, "Socket could not be cleanly closed.");
}
}
}
I have also tried with the clearLocalSocket() method i have written, but no used for my problem. So i tried to close the FileDescriptor. Hope it will help you and others facing the same issue.