Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid bluetooth receive continuos incomming data from paired device
    primarykey
    data
    text
    <p>I have used the below code to detect the active bluetooth devices and create a list of them. Once the active bluetooth device list is prepared we can select one device from list and send connection request to that device. Once the requested device accept connection request i need to get continuous incomming data signal from paired device.</p> <pre><code>protected void connect(BluetoothDevice device) { try { Log.d(TAG,"connect bluetooth"); // Create a Socket connection: need the server's UUID number of // registered Method m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class }); socket = (BluetoothSocket) m.invoke(device, 1); socket.connect(); Log.d(TAG, "&gt;&gt;Client connectted"); inputStream = socket.getInputStream(); socket.getOutputStream(); int read = -1; final byte[] bytes = new byte[2048]; while (true) { synchronized (obj1) { read = inputStream.read(bytes); Log.d(TAG, "read:" + read); if (read &gt; 0) { final int count = read; String str = SamplesUtils.byteToHex(bytes, count); // Log.d(TAG, "test1:" + str); String hex = hexString.toString(); if (hex == "") { hexString.append("&lt;--"); } else { if (hex.lastIndexOf("&lt;--") &lt; hex.lastIndexOf("--&gt;")) { hexString.append("\n&lt;--"); } } hexString.append(str); hex = hexString.toString(); // Log.d(TAG, "test2:" + hex); if (hex.length() &gt; maxlength) { try { hex = hex.substring(hex.length() - maxlength, hex.length()); hex = hex.substring(hex.indexOf(" ")); hex = "&lt;--" + hex; hexString = new StringBuffer(); hexString.append(hex); } catch (Exception e) { e.printStackTrace(); Log.e(TAG, "e", e); } } _handler.post(new Runnable() { public void run() { } }); } } } } catch (Exception e) { Log.e(TAG, "&gt;&gt;", e); Toast.makeText(getBaseContext(), getResources().getString(R.string.ioexception), Toast.LENGTH_SHORT).show(); return; } finally { if (socket != null) { try { Log.d(TAG, "&gt;&gt;Client Socket Close"); socket.close(); socket = null; // this.finish(); return; } catch (IOException e) { Log.e(TAG, "&gt;&gt;", e); } } } } </code></pre> <p>I need to detect continuous incomming data signals.Is it possible to do it. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload