Android Open Source - GlassToPhoneBluetooth Server Bluetooth Connection Thread






From Project

Back to project page GlassToPhoneBluetooth.

License

The source code is released under:

MIT License

If you think the Android project GlassToPhoneBluetooth 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 ktlab.lib.connection.bluetooth;
//from w ww. j a va 2  s . co m
import java.io.IOException;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothServerSocket;
import android.os.Message;
import android.util.Log;

public class ServerBluetoothConnectionThread extends BluetoothConnectionThread {

    private static final String TAG = "BluetoothConnection";

    private static final String SERVICE_NAME = "KTLab_Library";

    private BluetoothAdapter mBluetoothAdapter;
    private BluetoothServerSocket mServerSocket;

    public ServerBluetoothConnectionThread(Message msg) {
        super(msg);
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    }

    protected void getSocket() {

        // create server socket
        try {
            mServerSocket = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(SERVICE_NAME,
                    BluetoothConnection.SERVICE_UUID);
        } catch (IOException e) {
            Log.e(TAG, "failed to get server socekt", e);
            return;
        }

        // get socket
        try {
            mSocket = mServerSocket.accept();
        } catch (IOException e) {
            Log.e(TAG, "failed to get Bluetooth socket");
            mSocket = null;
        }

        // close server socket
        try {
            mServerSocket.close();
        } catch (IOException e) {
            Log.e(TAG, "failed to close ServerSocket");
        }
    }

    @Override
    public boolean close(){
        if (mServerSocket != null){
            try {
                mServerSocket.close();
            } catch (IOException e) {
            }
        }
        return super.close();
    }
}




Java Source Code List

com.space150.android.glass.camerazoom.DeviceSelectActivity.java
com.space150.android.glass.camerazoom.MainActivity.java
com.zlglassworks.glassbluetoothtest.DeviceSelectDialogFragment.java
com.zlglassworks.glassbluetoothtest.MainActivity.java
ktlab.lib.connection.CommandReceiveThread.java
ktlab.lib.connection.CommandReceiveThread.java
ktlab.lib.connection.CommandSendThread.java
ktlab.lib.connection.CommandSendThread.java
ktlab.lib.connection.ConnectionCallback.java
ktlab.lib.connection.ConnectionCallback.java
ktlab.lib.connection.ConnectionCommand.java
ktlab.lib.connection.ConnectionCommand.java
ktlab.lib.connection.ConnectionThread.java
ktlab.lib.connection.ConnectionThread.java
ktlab.lib.connection.Connection.java
ktlab.lib.connection.Connection.java
ktlab.lib.connection.bluetooth.BluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.BluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.BluetoothConnection.java
ktlab.lib.connection.bluetooth.BluetoothConnection.java
ktlab.lib.connection.bluetooth.ClientBluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.ClientBluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.ClientBluetoothConnection.java
ktlab.lib.connection.bluetooth.ClientBluetoothConnection.java
ktlab.lib.connection.bluetooth.ServerBluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.ServerBluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.ServerBluetoothConnection.java
ktlab.lib.connection.bluetooth.ServerBluetoothConnection.java