public class ServerBT extends Thread {
private static final String TAG = raspberrypi SERVER BT;
public ServerBT() {
BluetoothServerSocket tmp = null;
Method m;
try {
m = ConnectionBT.mDevice.getClass().getMethod(createRfcommSocket,
new Class[] {int.class});
tmp = (BluetoothServerSocket) m.invoke(ConnectionBT.mDevice, 1);
Log.d(TAG, creating connection SERVER BT);
}
catch (NoSuchMethodException e) { e.printStackTrace();}
catch (IllegalAccessException e) {e.printStackTrace();}
catch (IllegalArgumentException e) { e.printStackTrace(); }
catch (InvocationTargetException e) { e.printStackTrace(); }
ConnectionBT.mServerSocket = tmp;}
public void run() {
int bytesRead=-1;
String message=;
while (true)
{ message = ;
try {
ConnectionBT.mSocket = ConnectionBT.mServerSocket.accept();
}
catch (IOException e) { break; }
byte[] packetBytes = newbyte[bytesAvailable];
ConnectionBT.mInStream.read(packetBytes);
message = message + new String(packetBytes, 0, bytesRead - 1);
Log.d(TAG, message);
ConnectionBT.sensorActivity.setMessage(message);
}
}
catch (IOException e1) { e1.printStackTrace();}
try {
ConnectionBT.mServerSocket.close();
}
catch (IOException e) { e.printStackTrace(); }
break;
}
}
}
public void cancel() {
try {
ConnectionBT.mServerSocket.close();
}
catch (IOException e) { }
}
}