android.bluetooth.BluetoothServerSocket Java Examples

The following examples show how to use android.bluetooth.BluetoothServerSocket. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BluetoothServerService.java    From tilt-game-android with MIT License 6 votes vote down vote up
public AcceptThread(boolean secure) {
    _socketType = secure ? "Secure" : "Insecure";

    // Create a new listening server socket
    BluetoothServerSocket serverSocket = null;
    try {
        if (secure) {
            if (_debug) Log.d(TAG, "AcceptThread: started listening secure, uuid = " + _secureUuid + ", spd name = " + _secureSPDName);
            serverSocket = _adapter.listenUsingRfcommWithServiceRecord(_secureSPDName, _secureUuid);
        } else {
            if (_debug) Log.d(TAG, "AcceptThread: started listening insecure, uuid = " + _insecureUuid + ", spd name = " + _insecureSPDName);
            serverSocket = _adapter.listenUsingInsecureRfcommWithServiceRecord(_insecureSPDName, _insecureUuid);
        }
    } catch (IOException e) {
        Log.e(TAG, "AcceptThread: listen failed");
        e.printStackTrace();
    }

    _serverSocket = serverSocket;

    _isListening = true;
}
 
Example #2
Source File: BluetoothService.java    From NovarumBluetooth with MIT License 6 votes vote down vote up
public AcceptThread() 
{
    // Use a temporary object that is later assigned to mmServerSocket,
    // because mmServerSocket is final
    BluetoothServerSocket tmp = null;
    try 
    {
        // MY_UUID is the app's UUID string, also used by the client code
        tmp = bluetoothAdapter.listenUsingRfcommWithServiceRecord(SERVERNAME, UUID.fromString(DEFAULT_UUID));
    } 
    catch (IOException e) 
    { 
    	postError(e.getMessage());
    }
    
    mmServerSocket = tmp;
}
 
Example #3
Source File: NovarumbluetoothModule.java    From NovarumBluetooth with MIT License 6 votes vote down vote up
public AcceptThread() 
{
    // Use a temporary object that is later assigned to mmServerSocket,
    // because mmServerSocket is final
    BluetoothServerSocket tmp = null;
    try 
    {
        // MY_UUID is the app's UUID string, also used by the client code
        tmp = bluetoothAdapter.listenUsingRfcommWithServiceRecord(SERVERNAME, UUID.fromString(DEFAULT_UUID));
    } 
    catch (IOException e) 
    { 
    	postError(e.getMessage());
    }
    
    mmServerSocket = tmp;
}
 
Example #4
Source File: DirectMessageSession.java    From gilgamesh with GNU General Public License v3.0 6 votes vote down vote up
public AcceptThread(boolean secure) {
    BluetoothServerSocket tmp = null;
    mSocketType = secure ? "Secure":"Insecure";

    // Create a new listening server socket
    try {
        if (secure) {
            tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,
                MY_UUID_SECURE);
        } else {
            tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(
                    NAME_INSECURE, MY_UUID_INSECURE);
        }
    } catch (IOException e) {
        Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
    }
    mmServerSocket = tmp;
}
 
Example #5
Source File: MultiplexBluetoothTransport.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressLint("NewApi")
 @RequiresPermission(Manifest.permission.BLUETOOTH)
 public AcceptThread(boolean secure) {
 	synchronized(THREAD_LOCK){
     	//Log.d(TAG, "Creating an Accept Thread");
     	BluetoothServerSocket tmp = null;
     	mSocketType = secure ? "Secure":"Insecure";
     	// Create a new listening server socket
     	try {
         	if (secure) {
         		tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, SERVER_UUID);
         	}
     	} catch (IOException e) {
         	//Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
         	 //Let's try to shut down this thead
     	}catch(SecurityException e2){
     		//Log.e(TAG, "<LIVIO> Security Exception in Accept Thread - "+e2.toString());
     		interrupt();
     	}
     	mmServerSocket = tmp;
//Should only log on debug
     	//BluetoothSocket mySock = getBTSocket(mmServerSocket);
     	//Log.d(TAG, "Accepting Connections on SDP Server Port Number: " + getChannel(mySock) + "\r\n");
     }
 }
 
Example #6
Source File: BluetoothChatService.java    From android-BluetoothChat with Apache License 2.0 6 votes vote down vote up
public AcceptThread(boolean secure) {
    BluetoothServerSocket tmp = null;
    mSocketType = secure ? "Secure" : "Insecure";

    // Create a new listening server socket
    try {
        if (secure) {
            tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,
                    MY_UUID_SECURE);
        } else {
            tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(
                    NAME_INSECURE, MY_UUID_INSECURE);
        }
    } catch (IOException e) {
        Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
    }
    mmServerSocket = tmp;
    mState = STATE_LISTEN;
}
 
Example #7
Source File: BluetoothUtility.java    From SimpleBluetoothLibrary with Apache License 2.0 6 votes vote down vote up
public AcceptThread() {
    // Use a temporary object that is later assigned to mmServerSocket,
    // because mmServerSocket is final
    BluetoothServerSocket tmp = null;
    try {
        // MY_UUID is the app's UUID string, also used by the client code
        tmp = bluetoothAdapter.listenUsingRfcommWithServiceRecord(SERVER_NAME, SERVER_UUID);
    } catch (IOException e) { }
    mmServerSocket = tmp;

    if(bluetoothHandler != null) {
        bluetoothHandler
                .obtainMessage(BluetoothHandler.MESSAGE_WAIT_FOR_CONNECTION)
                .sendToTarget();
    }
}
 
Example #8
Source File: BluetoothService.java    From AndroidSmoothBluetooth with Apache License 2.0 6 votes vote down vote up
public AcceptThread(boolean isAndroid, boolean secure) {
    BluetoothServerSocket tmp = null;

    // Create a new listening server socket
    try {
        if (secure) {
            if(isAndroid)
                tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, UUID_ANDROID_DEVICE);
            else
                tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, UUID_OTHER_DEVICE);
        } else {
            if(isAndroid)
                tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_SECURE, UUID_ANDROID_DEVICE);
            else
                tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_SECURE, UUID_OTHER_DEVICE);
        }
    } catch (IOException e) { }
    mmServerSocket = tmp;
}
 
Example #9
Source File: SerialInterface_BT.java    From PodEmu with GNU General Public License v3.0 6 votes vote down vote up
public AcceptThread()
{
    BluetoothServerSocket tmp = null;

    // Create a new listening server socket
    try
    {
        PodEmuLog.debug("SIBT: AcceptThread connecting with btdev_uuid_idx=" + btdev_uuid_idx);
        tmp = btAdapter.listenUsingRfcommWithServiceRecord(getName(), BTDEV_UUID[btdev_uuid_idx]);
    }
    catch (IOException e)
    {
        PodEmuLog.debug("SIBT: AcceptThread listen() failed");
        PodEmuLog.printStackTrace(e);
    }
    mmServerSocket = tmp;
}
 
Example #10
Source File: BluetoothChatService.java    From connectivity-samples with Apache License 2.0 6 votes vote down vote up
public AcceptThread(boolean secure) {
    BluetoothServerSocket tmp = null;
    mSocketType = secure ? "Secure" : "Insecure";

    // Create a new listening server socket
    try {
        if (secure) {
            tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE,
                    MY_UUID_SECURE);
        } else {
            tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(
                    NAME_INSECURE, MY_UUID_INSECURE);
        }
    } catch (IOException e) {
        Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
    }
    mmServerSocket = tmp;
    mState = STATE_LISTEN;
}
 
Example #11
Source File: BluetoothIOGateway.java    From ELM327 with Apache License 2.0 6 votes vote down vote up
public AcceptThread(boolean secure)
{
    BluetoothServerSocket tmp = null;
    mSocketType = secure ? "Secure" : "Insecure";

    // Create a new listening server socket
    try
    {
        if (secure)
        {
            tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE);
        }
        else
        {
            tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_INSECURE, MY_UUID_INSECURE);
        }
    }
    catch (IOException e)
    {
        MyLog.e(TAG, "Listen to " + mSocketType + " socket type failed. More: ", e);
    }

    mmServerSocket = tmp;
}
 
Example #12
Source File: BluetoothServerTask.java    From secureit with MIT License 6 votes vote down vote up
public BluetoothServerTask(Context context) throws NoBluetoothException {
	
	Log.i("BluetoothServerTask", "Created");
	mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
	if (mBluetoothAdapter == null) {
	    // Device does not support Bluetooth
		throw new NoBluetoothException();
		
	}
	this.context = context;
	Log.i("BluetoothServerTask", "Got adapter");
    // Use a temporary object that is later assigned to mmServerSocket,
    // because mmServerSocket is final
    BluetoothServerSocket tmp = null;
    try {
        // MY_UUID is the app's UUID string, also used by the client code
        tmp = mBluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord(
        		Remote.BLUETOOTH_NAME, 
        		Remote.BLUETOOTH_UUID);
        Log.i("BluetoothServerTask", "Created insecure server socket");
    } catch (IOException e) { 
    	throw new NoBluetoothException();
    }
    mmServerSocket = tmp;
}
 
Example #13
Source File: CbtServiceListener.java    From ClassicBluetooth with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化
 *
 * @return
 */
public void init(BluetoothAdapter bluetoothAdapter, ServiceListenerCallback callback) {
    mListenerCallback = callback;
    if (mBluetoothAdapter != null || mBluetoothServerSocket != null) {
        return;
    }
    mBluetoothAdapter = bluetoothAdapter;
    BluetoothServerSocket tmp = null;
    try {
        // 明文传输,无需配对
        // adapter.listenUsingInsecureRfcommWithServiceRecord(TAG, SPP_UUID);
        // 加密传输,会自动执行配对
        tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(CbtConstant.CBT_NAME, CbtConstant.CBT_UUID);
    } catch (IOException e) {
        mListenerCallback.onStartError(e);
        CbtLogs.e(e.getMessage());
        return;
    }
    mBluetoothServerSocket = tmp;
    listener();
}
 
Example #14
Source File: BluetoothManager.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * コンストラクタ
 * @param secure セキュア接続を待機するならtrue
 */
public ListeningThread(final boolean secure) {
	super("ListeningThread:" + mName);

	// Create a new listening server socket
	BluetoothServerSocket tmp = null;
	try {
		if (secure) {
		// セキュアな接続を行うためのBluetoothServerSocketを生成
			tmp = mAdapter.listenUsingRfcommWithServiceRecord(mName, mSecureProfileUUID);
		} else {
			tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(mName, mInSecureProfileUUID);
		}
	} catch (final IOException e) {
		Log.w(TAG, e);
	}
	mmServerSocket = tmp;
}
 
Example #15
Source File: GrblBluetoothSerialService.java    From grblcontroller with GNU General Public License v3.0 6 votes vote down vote up
public AcceptThread(boolean secure) {
    BluetoothServerSocket tmp = null;
    mSocketType = secure ? "Secure" : "Insecure";

    // Create a new listening server socket
    try {
        if (secure) {
            tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, MY_UUID_SECURE);
        } else {
            tmp = mAdapter.listenUsingInsecureRfcommWithServiceRecord(NAME_INSECURE, MY_UUID_INSECURE);
        }
    } catch (IOException | NullPointerException e) {
        Log.e(TAG, "Socket Type: " + mSocketType + "listen() failed", e);
    }
    mmServerSocket = tmp;
    mState = STATE_LISTEN;
}
 
Example #16
Source File: ServerThread.java    From BluetoothStudy with Apache License 2.0 5 votes vote down vote up
public ServerThread(BluetoothAdapter bluetoothAdapter, Handler handler) {
    this.bluetoothAdapter = bluetoothAdapter;
    this.uiHandler = handler;
    BluetoothServerSocket tmp = null;
    try {
        tmp = bluetoothAdapter.listenUsingRfcommWithServiceRecord(Params.NAME, UUID.fromString(Params.UUID));
    } catch (IOException e) {
        e.printStackTrace();
    }
    serverSocket = tmp;
    Log.e(TAG, "-------------- do new()");
}
 
Example #17
Source File: BluetoothConnectionHelper.java    From DataLogger with MIT License 5 votes vote down vote up
public AcceptThread(int index) {
    mIndex = index;
    BluetoothServerSocket tmp = null;

    // Create a new listening server socket
    try {
        tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(
                NAME,
                UUID.fromString(mUUIDs[mIndex]));
    } catch (IOException e) {
        Log.e(TAG, "::AcceptThread Socket listen() at "+ mIndex + " failed.", e);
    }
    mmServerSocket = tmp;
}
 
Example #18
Source File: BluetoothServer.java    From EFRConnect-android with Apache License 2.0 5 votes vote down vote up
public BluetoothServer(BluetoothAdapter bluetoothAdapter, String serviceName, UUID serviceUUID) {
    // Use a temporary object that is later assigned to mmServerSocket,
    // because mmServerSocket is final
    BluetoothServerSocket tmp = null;
    try {
        // MY_UUID is the app's UUID string, also used by the client code
        tmp = bluetoothAdapter.listenUsingRfcommWithServiceRecord(serviceName, serviceUUID);
    } catch (IOException ignored) {
    }
    serverSocket = tmp;
}
 
Example #19
Source File: BluetoothService.java    From Chorus-RF-Laptimer with MIT License 5 votes vote down vote up
public AcceptThread(boolean isAndroid) {
    BluetoothServerSocket tmp = null;

    // Create a new listening server socket
    try {
        if(isAndroid)
            tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, UUID_ANDROID_DEVICE);
        else
            tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, UUID_OTHER_DEVICE);
    } catch (IOException e) { }
    mmServerSocket = tmp;
}
 
Example #20
Source File: BluetoothService.java    From BluetoothSPPLibrary with Apache License 2.0 5 votes vote down vote up
public AcceptThread(boolean isAndroid) {
    BluetoothServerSocket tmp = null;

    // Create a new listening server socket
    try {
        if(isAndroid)
            tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, UUID_ANDROID_DEVICE);
        else
            tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME_SECURE, UUID_OTHER_DEVICE);
    } catch (IOException e) { }
    mmServerSocket = tmp;
}
 
Example #21
Source File: Server_Fragment.java    From bluetooth with Apache License 2.0 5 votes vote down vote up
public AcceptThread() {
    BluetoothServerSocket tmp = null;
    // Create a new listening server socket
    try {
        tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(MainActivity.NAME, MainActivity.MY_UUID);
    } catch (IOException e) {
        mkmsg("Failed to start server\n");
    }
    mmServerSocket = tmp;
}
 
Example #22
Source File: blueToothDemo.java    From bluetooth with Apache License 2.0 5 votes vote down vote up
public AcceptThread() {
    BluetoothServerSocket tmp = null;
    // Create a new listening server socket
    try {
        tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
    } catch (IOException e) {
        mkmsg("Failed to start server\n");
    }
    mmServerSocket = tmp;
}
 
Example #23
Source File: Server_Fragment.java    From bluetooth with Apache License 2.0 5 votes vote down vote up
public AcceptThread() {
	BluetoothServerSocket tmp = null;
	// Create a new listening server socket
	try {
		tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord(MainActivity.NAME, MainActivity.MY_UUID);
	} catch (IOException e) {
		mkmsg("Failed to start server\n");
	}
	mmServerSocket = tmp;
}
 
Example #24
Source File: BluetoothManager.java    From retrowatch with Apache License 2.0 5 votes vote down vote up
public AcceptThread() {
    BluetoothServerSocket tmp = null;

    // Create a new listening server socket
    try {
        tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
    } catch (IOException e) {
        Logs.e(TAG, "listen() failed" + e.toString());
    }
    mmServerSocket = tmp;
}
 
Example #25
Source File: BluetoothManager.java    From retrowatch with Apache License 2.0 5 votes vote down vote up
public AcceptThread() {
    BluetoothServerSocket tmp = null;

    // Create a new listening server socket
    try {
        tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
    } catch (IOException e) {
        Logs.e(TAG, "listen() failed" + e.toString());
    }
    mmServerSocket = tmp;
}
 
Example #26
Source File: BluetoothManager.java    From retroband with Apache License 2.0 5 votes vote down vote up
public AcceptThread() {
    BluetoothServerSocket tmp = null;

    // Create a new listening server socket
    try {
        tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
    } catch (IOException e) {
        Log.e(TAG, "listen() failed" + e.toString());
    }
    mmServerSocket = tmp;
}
 
Example #27
Source File: BluetoothChatService.java    From Car_remote_control with GNU General Public License v3.0 5 votes vote down vote up
public AcceptThread()
{
	BluetoothServerSocket tmp = null;

	try
	{
		tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
	}
	catch (IOException e)
	{
		Log.e(TAG, "listen() failed", e);
	}
	mmServerSocket = tmp;
}
 
Example #28
Source File: SyncStreamingService.java    From boogie-board-sync-sdk-android with MIT License 5 votes vote down vote up
public AcceptThread() {
    BluetoothServerSocket tmp = null;

    // Create a new listening server socket.
    try {
        tmp = mBluetoothAdapter.listenUsingInsecureRfcommWithServiceRecord("Sync Streaming Profile", LISTEN_UUID);
    } catch (IOException e) {
        Log.e(TAG, "listen() failed", e);
    }
    mServerSocket = tmp;
}
 
Example #29
Source File: BluetoothManager.java    From BTChat with GNU General Public License v3.0 5 votes vote down vote up
public AcceptThread() {
    BluetoothServerSocket tmp = null;

    // Create a new listening server socket
    try {
        tmp = mAdapter.listenUsingRfcommWithServiceRecord(NAME, MY_UUID);
    } catch (IOException e) {
        Log.e(TAG, "listen() failed" + e.toString());
    }
    mmServerSocket = tmp;
}
 
Example #30
Source File: BluetoothService.java    From UnityBluetoothPlugin with Apache License 2.0 5 votes vote down vote up
public AcceptThread() {
    BluetoothServerSocket tmp = null;

    try {
        tmp = BluetoothService.this.mBtAdapter.listenUsingRfcommWithServiceRecord("BluetoothPlugin", BluetoothService.MY_UUID);
    } catch (IOException e) {
        Log.e(TAG, "listen() failed", e);
    }

    this.mmServerSocket = tmp;
}