Android BluetoothSocket - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android BluetoothSocket class.

This code example shows how to use the following methods:getInputStream, getOutputStream
            InputStream tmpIn = null;
            OutputStream tmpOut = null;
 
            // Get the BluetoothSocket input and output streams 
            try { 
                tmpIn = socket.getInputStream();
                tmpOut = socket.getOutputStream();
            } catch (IOException e) {
                Log.e(TAG, "temp sockets not created", e);
            } 
 
            mmInStream = new DataInputStream(tmpIn);
            mmOutStream = new DataOutputStream(tmpOut);
//            mmInStream = new DataInputStream(new BufferedInputStream(tmpIn, 8192)); 
//            mmOutStream = new DataOutputStream(new BufferedOutputStream(tmpOut, 8192)); 
        } 
 
        public void run() { 
            Log.i(TAG, "BEGIN mConnectedThread");
 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getOutputStream
	public final boolean isConnected() { 
		return mConnected;
	} 
	 
	public final void write(byte[] data, int size) throws IOException {
		mSocket.getOutputStream().write(data, 0, size);
	} 
 
	public final void kill() { 
		try { 
			mStop = true;
			mSocket.getOutputStream().close();
			mSocket.getInputStream().close();
			mServer.close();
		} catch (Exception e) {
		} 
		try { 
			join();
		} catch (InterruptedException e) {
		} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close, connect, getInputStream, getOutputStream, getRemoteDevice
    private long timeout;
 
    public ConnectThread(Rfcomm rfcomm, BluetoothDevice device, boolean secure, long timeout) {
    	this.rfcomm = rfcomm;
        mAdapter = BluetoothAdapter.getDefaultAdapter();
    	mDevice = device;
        BluetoothSocket tmp = null;
        mSocketType = secure ? "Secure" : "Insecure";
        this.timeout = timeout;
 
        // Get a BluetoothSocket for a connection with the 
        // given BluetoothDevice 
        try { 
            if (secure) {
                tmp = device.createRfcommSocketToServiceRecord(
                        rfcomm.getSecureUUID());
            } else { 
                tmp = device.createInsecureRfcommSocketToServiceRecord(
                        rfcomm.getUnsecureUUID());
            } 

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close
            connected(mmSocket, mmDevice, mSocketType, false);
        } 
 
        public void cancel() { 
            try { 
                mmSocket.close();
            } catch (IOException e) {
                Log.e(TAG, "close() of connect " + mSocketType + " socket failed", e);
            } 
        } 
    } 
 
    /** 
     * This thread runs during a connection with a remote device. 
     * It handles all incoming and outgoing transmissions. 
     */ 
    private class ConnectedThread extends Thread {
        private final BluetoothSocket mmSocket;
        private final DataInputStream mmInStream;
        private final DataOutputStream mmOutStream;
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getInputStream, getOutputStream
            InputStream tmpIn = null;
            OutputStream tmpOut = null;
 
            // Get the BluetoothSocket input and output streams 
            try { 
                tmpIn = socket.getInputStream();
                tmpOut = socket.getOutputStream();
            } catch (IOException e) {
                Log.e(TAG, "temp sockets not created", e);
            } 
 
            mmInStream = tmpIn;
            mmOutStream = tmpOut;
        } 
 
        public void run() { 
            Log.i(TAG, "BEGIN mConnectedThread");
            byte[] buffer = new byte[1024];
            int bytes;
 
9
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:connect, getInputStream, getOutputStream, getRemoteDevice
 
  BluetoothSocket socket;
 
  BluetoothHelper(BluetoothSocket _socket)
    throws IOException { 
    super(_socket.getRemoteDevice().getAddress());
    socket = _socket;
 
    super.set(socket.getInputStream(), socket.getOutputStream());
  } 
 
  public void close() { 
    super.close(); 
 
    try { 
      socket.close();
    } catch (IOException e) {
      /* ignore... what else should we do if closing the socket 
         fails? */ 
    } 

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getInputStream
		    } 
		} 
		 
		@Override 
		public InputStream getInputStream() throws IOException {
			return mmSocket.getInputStream();
		} 
		 
		@Override 
		public OutputStream getOutputStream() throws IOException {
			return mmSocket.getOutputStream();
		} 
		 
		@Override 
		public void close() throws IOException { 
			if (mmSocket != null) {
				mmSocket.close();
			} 
		} 
	} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getInputStream, getOutputStream, getRemoteDevice
    private ConnectedThreadListener listener;
 
    public ConnectedThread(BluetoothSocket socket, String socketType, long timeout) {
        Log.d(TAG, "create ConnectedThread: " + socketType);
        mSocket = socket;
        mDevice = mSocket.getRemoteDevice();
        InputStream tmpIn = null;
        OutputStream tmpOut = null;
 
        // Get the BluetoothSocket input and output streams 
        try { 
            tmpIn = socket.getInputStream();
            tmpOut = socket.getOutputStream();
        } catch (IOException e) {
            Log.e(TAG, "temp sockets not created", e);
        } 
 
        mInStream = tmpIn;
        mOutStream = tmpOut;
        mTimeoutThread = new TimeoutThread(timeout);
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:close, connect
 
        // Make a connection to the BluetoothSocket 
        try { 
            // This is a blocking call and will only return on a 
            // successful connection or an exception 
            mmSocket.connect();
        } catch (IOException e) {
            mService.connectionFailed();
            Log.e(TAG, "connection failure", e);
            // Close the socket 
            try { 
                mmSocket.close();
            } catch (IOException e2) {
                Log.e(TAG, "unable to close() socket during connection failure", e2);
            } 
            return; 
        } 
 
        // Start the connected thread 
        mService.connected(mmSocket);

8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getInputStream, getOutputStream
            InputStream tmpIn = null;
            OutputStream tmpOut = null;
 
            // Get the BluetoothSocket input and output streams 
            try { 
                tmpIn = socket.getInputStream();
                tmpOut = socket.getOutputStream();
            } catch (IOException e) {
                Log.e(TAG, "temp sockets not created", e);
            } 
 
            mmInStream = tmpIn;
            mmOutStream = tmpOut;
        } 
 
        public void run() { 
            Log.i(TAG, "BEGIN mConnectedThread");
            byte[] buffer = new byte[1024];
            int bytes;
 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android BluetoothSocket Questions & Answers:

See Code Examples for Android BluetoothSocket Methods: