) ;. registerListener (this, mAccel, SensorManager.SENSOR_DELAY_NORMAL);
}
@ Overridevoid onPause () {.onPause () ;. BT_onPause () ;. unregisterListener (this);
}
@ Overridevoid onActivityResult (int requestCode, int resultCode, Intent data) {();
} void onAccuracyChanged (Sensor arg0, int arg1) {}
}.javacom.dum_car;java.io.IOException;java.io.InputStream;java.io.OutputStream;java.lang.reflect.Method;java.util.UUID;android.bluetooth.BluetoothAdapter;android.bluetooth.BluetoothDevice;android.bluetooth.BluetoothSocket;android.content.Context;android.os.Build;android.os.Handler;android.util.Log;class cBluetooth {final static String TAG= BL_4WD raquo ;; static BluetoothAdapter btAdapter=null; BluetoothSocket btSocket=null; OutputStream outStream=null; ConnectedThread mConnectedThread; static final UUID MY_UUID=UUID.fromString ( 00001101-0000-1000-8000-00805F9B34FB ); final Handler mHandler; final static int BL_NOT_AVAILABLE=1; final static int BL_INCORRECT_ADDRESS=2; final static int BL_REQUEST_ENABLE=3; final static int BL_SOCKET_FAILED=4; final static int RECIEVE_MESSAGE=5; (Context context, Handler handler) {= BluetoothAdapter.getDefaultAdapter ();=handler; (btAdapter == null) {.sendEmptyMessage (BL_NOT_AVAILABLE) ;;
} void checkBTState () {(btAdapter == null) {.sendEmptyMessage (BL_NOT_AVAILABLE);
} else {(btAdapter.isEnabled ()) {.d (TAG, Bluetooth ON );
} else {.sendEmptyMessage (BL_REQUEST_ENABLE);
} BluetoothSocket createBluetoothSocket (BluetoothDevice device) throws IOException {(Build.VERSION.SDK_INT gt;=10) {{Method m=device.getClass (). getMethod ( createInsecureRfcommSocketToServiceRecord raquo ;, new Class [ ] {UUID.class}); (BluetoothSocket) m.invoke (device, MY_UUID);
} catch (Exception e) {.e (TAG, Could not create Insecure RFComm Connection , e);
} device.createRfcommSocketToServiceRecord (MY_UUID); boolean BT_Connect (String address, boolean listen_InStream) {.d (TAG, ... On Resume ... ); connected=false;(!BluetoothAdaptereckBluetoothAddress(address)){.sendEmptyMessage(BL_INCORRECT_ADDRESS);false;
} {device=btAdapter.getRemoteDevice (address); {= createBluetoothSocket (device);
} catch (IOException e1) {
Log.e (TAG, In BT_Connect () socket create failed: + e1.getMessage ());
mHandler.sendEmptyMessage (BL_SOCKET_FAILED);
return false;
}
btAdapter.cancelDiscovery () ;. d (TAG, ... Connecting ... );
try {
btSocket.connect ();
Log.d (TAG, ... Connection ok ... );
} catch (IOException e) {
try {
btSocket.close ();
} catch (IOException e2) {
Log.e (TAG, In BT_Connect () unable to close socket during connection failure + e2.getMessage ());
mHandler.sendEmptyMessage (BL_SOCKET_FAILED);
return false;
}. d (TAG, ... Create Socket ... ); {
outStream=btSocket.getOutputStream ();
connected=true;
} catch (IOException e) {
Log.e (TAG, In BT_Connect () output stream creation failed: + e.getMessage ());
mHandler.sendEmptyMessage (BL_SOCKET_FAILED);
return false;
} (listen_InStream) {= new ConnectedThread ();
mConnectedThread.start ();
} connected;
} void BT_onPause () {.d (TAG, ... On Pause ... ); (outStream!=null) {{
outStream.flush ();
} catch (IOException e) {
Log.e (TAG, In onPause () and failed to flush output stream: + e.getMessage ());
mHandler.sendEmptyMessage (BL_SOCKET_FAILED);
return;
} (btSocket!=null) {
try {
btSocket.close ();
} catch (IOException e2) {
Log.e (TAG, In onPause () and failed to close socket. + e2.getMessage ());
mHandler.sendEmptyMessage (BL_SOCKET_FAILED);
return;
} void sendData (String message) {[] msgBuffer=message.getBytes () ;. i (TAG, Send data: + message); (outStream!=null) {
try {
...