Android Open Source - wrist.io Bluetooth Manager






From Project

Back to project page wrist.io.

License

The source code is released under:

GNU General Public License

If you think the Android project wrist.io listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.hackedio.wristio.bluetooth;
/*from   ww w.  j av  a  2s. c om*/
import java.io.IOException;
import java.io.OutputStream;

import android.bluetooth.BluetoothSocket;

//Copied from http://developer.android.com/guide/topics/connectivity/bluetooth.html#Permissions (ConnectedThread)
public class BluetoothManager extends Thread{

  private final BluetoothSocket mmSocket;
//    private final InputStream mmInStream;
    private final OutputStream mmOutStream;
    
    private boolean enabled = true;
 
    public BluetoothManager(BluetoothSocket socket) {
        mmSocket = socket;
//        InputStream tmpIn = null;
        OutputStream tmpOut = null;
 
        // Get the input and output streams, using temp objects because
        // member streams are final
        try {
//            tmpIn = socket.getInputStream();
            tmpOut = socket.getOutputStream();
        } catch (IOException e) { }
 
//        mmInStream = tmpIn;
        mmOutStream = tmpOut;
    }
 
    public void run() {
      
//      TwitterWristManager twm = new TwitterWristManager(this);
//      twm.start();
      
        // Keep listening to the InputStream until an exception occurs
        while (enabled) {
          try {
        Thread.sleep(25);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
        }
    }

    /* Call this from the main activity to send data to the remote device */
    public void write(byte[] bytes) {
        try {
            mmOutStream.write(bytes);
        } catch (IOException e) { }
    }
 
    /* Call this from the main activity to shutdown the connection */
    public void cancel() {
        try {
            mmSocket.close();
            enabled = false;
        } catch (IOException e) { }
    }

  public boolean isEnabled() {
    return enabled;
  }
    
}




Java Source Code List

org.hackedio.wristio.ControlActivity.java
org.hackedio.wristio.bluetooth.BluetoothManager.java
org.hackedio.wristio.notification.NotificationService.java
org.hackedio.wristio.twitter.TwitterWristManager.java
org.hackedio.wristio.util.AlertUtil.java
org.hackedio.wristio.util.BluetoothUtil.java