Java Code Examples for android.bluetooth.BluetoothSocket#getInputStream()

The following examples show how to use android.bluetooth.BluetoothSocket#getInputStream() . 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: BluetoothService.java    From Android-HC05-App with MIT License 6 votes vote down vote up
public ConnectedThread(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) {
        Log.e(Constants.TAG, "Temp sockets not created", e);
    }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
}
 
Example 2
Source File: BluetoothChatService.java    From Car_remote_control with GNU General Public License v3.0 6 votes vote down vote up
public ConnectedThread(BluetoothSocket socket)
{
	Log.d(TAG, "create ConnectedThread");
	mmSocket = socket;
	InputStream tmpIn = null;
	OutputStream tmpOut = null;

	try
	{
		tmpIn = socket.getInputStream();
		tmpOut = socket.getOutputStream();
	}
	catch (IOException e)
	{
		Log.e(TAG, "temp sockets not created", e);
	}

	mmInStream = tmpIn;
	mmOutStream = tmpOut;
}
 
Example 3
Source File: BluetoothManager.java    From retrowatch with Apache License 2.0 6 votes vote down vote up
public ConnectedThread(BluetoothSocket socket) {
    Log.d(TAG, "create ConnectedThread");
    mmSocket = socket;
    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;
}
 
Example 4
Source File: BluetoothClient.java    From EFRConnect-android with Apache License 2.0 6 votes vote down vote up
private void manageConnectedSocket(BluetoothSocket socket) throws IOException {
    synchronized (this) {
        os = socket.getOutputStream();
    }

    is = socket.getInputStream();
    //noinspection InfiniteLoopStatement
    while (true) {
        // While loop will terminate only upon an actual IOException
        // or upon a close of the socket that will also cause an IOException.
        int didRead = is.read(buffer);
        //noinspection StatementWithEmptyBody
        if (didRead > 0) {
            // TODO
        }
    }
}
 
Example 5
Source File: BluetoothManager.java    From libcommon with Apache License 2.0 6 votes vote down vote up
public ReceiverThread(final BluetoothSocket socket) {
			super("ReceiverThread:" + mName, socket);
//			if (DEBUG) Log.d(TAG, "create ReceiverThread:");
			InputStream tmpIn = null;
			OutputStream tmpOut = null;

			// 受信待ち用のInputStreamと送信用のOutputStreamを取得する
			// 普通のInputStreamはBufferedInputStreamで、OutputStreamは
			// BufferedOutputStreamでラップするけどここで取得されるStreamを
			// ラップすると上手く動かないみたい
			try {
				tmpIn = socket.getInputStream();
				tmpOut = socket.getOutputStream();
			} catch (final IOException e) {
				Log.e(TAG, "temp sockets not created", e);
			}

			mmInStream = tmpIn;
			mmOutStream = tmpOut;
		}
 
Example 6
Source File: BluetoothManager.java    From retroband with Apache License 2.0 6 votes vote down vote up
public ConnectedThread(BluetoothSocket socket) {
    Log.d(TAG, "create ConnectedThread");
    mmSocket = socket;
    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;
}
 
Example 7
Source File: ConnectedThread.java    From Android-Simple-Bluetooth-Example with MIT License 6 votes vote down vote up
public ConnectedThread(BluetoothSocket socket, Handler handler) {
    mmSocket = socket;
    mHandler = handler;
    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;
}
 
Example 8
Source File: BtCommService.java    From AndrOBD with GNU General Public License v3.0 6 votes vote down vote up
BtWorkerThread(BluetoothSocket socket, String socketType)
{
	log.log(Level.FINE, "create BtWorkerThread: " + socketType);
	mmSocket = socket;
	InputStream tmpIn = null;
	OutputStream tmpOut = null;

	// Get the BluetoothSocket input and output streams
	try
	{
		tmpIn = socket.getInputStream();
		tmpOut = socket.getOutputStream();
	} catch (IOException e)
	{
		log.log(Level.SEVERE, "temp sockets not created", e);
	}

	mmInStream = tmpIn;
	mmOutStream = tmpOut;
	// set streams
	ser.setStreams(mmInStream, mmOutStream);
}
 
Example 9
Source File: BluetoothChatService.java    From android-BluetoothChat with Apache License 2.0 6 votes vote down vote up
public ConnectedThread(BluetoothSocket socket, String socketType) {
    Log.d(TAG, "create ConnectedThread: " + socketType);
    mmSocket = socket;
    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;
    mState = STATE_CONNECTED;
}
 
Example 10
Source File: BluetoothService.java    From BluetoothSPPLibrary with Apache License 2.0 5 votes vote down vote up
public ConnectedThread(BluetoothSocket socket, String socketType) {
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the BluetoothSocket input and output streams
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) { }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
}
 
Example 11
Source File: NXTTalker.java    From nxt-remote-control with Apache License 2.0 5 votes vote down vote up
public ConnectedThread(BluetoothSocket socket) {
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;
    
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) {
        e.printStackTrace();
    }
    
    mmInStream = tmpIn;
    mmOutStream = tmpOut;
}
 
Example 12
Source File: SyncStreamingService.java    From boogie-board-sync-sdk-android with MIT License 5 votes vote down vote up
public ConnectedThread(BluetoothSocket socket) {
    Log.d(TAG, "create ConnectedThread: ");
    mSocket = socket;
    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);
    }

    mInputStream = tmpIn;
    mOutputStream = tmpOut;
}
 
Example 13
Source File: BluetoothService.java    From SimpleBluetoothLibrary with Apache License 2.0 5 votes vote down vote up
public ConnectedThread(BluetoothSocket socket) {
            mmSocket = socket;
            bluetoothSocket = 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) {
//                Log.d("ConnectedThread", e.getMessage());
            }

            mInputStream = tmpIn;
            mOutputStream = tmpOut;
        }
 
Example 14
Source File: GodotBluetooth.java    From GodotBluetooth with MIT License 5 votes vote down vote up
public ConnectedThread(BluetoothSocket newSocket) {

            InputStream tmpIn = null;
            OutputStream tmpOut = null;

            try {
                tmpIn = newSocket.getInputStream();
                tmpOut = newSocket.getOutputStream();
            } catch (IOException e) { }

            mmInStream = tmpIn;
            mmOutStream = tmpOut;
        }
 
Example 15
Source File: BluetoothChatService.java    From AndroidDemo with MIT License 5 votes vote down vote up
public ConnectedThread(BluetoothSocket bluetoothSocket) {
            this.bluetoothSocket = bluetoothSocket;
            try {
                inputStream = bluetoothSocket.getInputStream();
                outputStream = bluetoothSocket.getOutputStream();
            } catch (IOException e) {
//                e.printStackTrace();
            }
        }
 
Example 16
Source File: BluetoothService.java    From Chorus-RF-Laptimer with MIT License 5 votes vote down vote up
public ConnectedThread(BluetoothSocket socket, String socketType) {
    mmSocket = socket;
    InputStream tmpIn = null;
    OutputStream tmpOut = null;

    // Get the BluetoothSocket input and output streams
    try {
        tmpIn = socket.getInputStream();
        tmpOut = socket.getOutputStream();
    } catch (IOException e) { }

    mmInStream = tmpIn;
    mmOutStream = tmpOut;
}
 
Example 17
Source File: BluetoothConnectionHelper.java    From DataLogger with MIT License 5 votes vote down vote up
public ConnectedThread(BluetoothSocket socket, int index) {
//            Log.d(TAG, "create ConnectedThread");
            mmSocket = socket;
            mIndex = index;
            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, "::ConnectedThread Input/Output stream sockets not created", e);
            }

            mmInStream = tmpIn;
            mmOutStream = tmpOut;
        }
 
Example 18
Source File: BluetoothActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
private String listenForMessages(BluetoothSocket socket,
                                 StringBuilder incoming) {
  String result = "";
  mListening = true;

  int bufferSize = 1024;
  byte[] buffer = new byte[bufferSize];

  try {
    InputStream instream = socket.getInputStream();
    int bytesRead = -1;
    while (mListening) {
      bytesRead = instream.read(buffer);
      if (bytesRead != -1) {
        while ((bytesRead == bufferSize) && (buffer[bufferSize-1] != 0)) {
          result = result + new String(buffer, 0, bytesRead - 1);
          bytesRead = instream.read(buffer);
        }

        result = result + new String(buffer, 0, bytesRead - 1);
        incoming.append(result);
      }
    }
  } catch (IOException e) {
    Log.e(TAG, "Message receive failed.", e);
  }
  return result;
}
 
Example 19
Source File: TaskerFireReceiver.java    From sony-headphones-control with GNU General Public License v3.0 5 votes vote down vote up
static void sendPacket(BluetoothSocket socket, byte[] data) throws IOException, InterruptedException {
        OutputStream o = socket.getOutputStream();
        InputStream i = socket.getInputStream();
        byte[] packet = new byte[data.length + 3];
        packet[0] = 0x3e;
        packet[packet.length - 1] = 0x3c;
        byte crc = 0;
        for (int j = 0; j < data.length; j++) {
            crc += data[j];
            packet[j + 1] = data[j];
        }
        packet[packet.length - 2] = crc;
        o.write(packet);

        byte[] buffer = new byte[256];
        Date date = new Date();
        while (new Date().getTime() - date.getTime() < 200) {
            if (i.available() > 0) {
                int r = i.read(buffer);
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < r; j++) {
                    sb.append(String.format(" %02x", buffer[j]));
                }
//                Log.i(TAG, "Read: " + r + " bytes:" + sb);
                break;
            }
            Thread.sleep(50);
        }
    }
 
Example 20
Source File: Bluetooth.java    From Makeblock-App-For-Android with MIT License 5 votes vote down vote up
public ConnectedThread(BluetoothSocket socket){
	mmSocket = socket;
	mRx = new ArrayList<Byte>();
	InputStream tmpIn = null;
	OutputStream tmpOut = null;
	
	try {
		tmpIn = socket.getInputStream();
		tmpOut = socket.getOutputStream();
	} catch (IOException e) {
		e.printStackTrace();
	}
	mmInStream = tmpIn;
	mmOutStream = tmpOut;
}