Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read data from bluetooth barcode scanner Symbol CS3070 to Android Device
    primarykey
    data
    text
    <p>In my project i have to read barcodes using barcode scanner Symbol CS3070 through bluetooth. i.e; i have to establish a connection between android device and barcode scanner through bluetooth. Can any one tell me how to read values from barcode reader and how to setup for communication? I've already read the <a href="http://developer.android.com/guide/topics/wireless/bluetooth.html">Bluetooth Developer Guide</a>, and I don't want to use Barcode Reader in Bluetooth Keyboard Emulation (HID) mode (I've some textview that can be filled using soft keyboard and Barcode Reader and I can't control the focus)</p> <p>I'd use a thread like this to communicate with a reader</p> <pre><code> private class BarcodeReaderThread extends Thread { private final BluetoothServerSocket mmServerSocket; public BarcodeReaderThread(UUID UUID_BLUETOOTH) { // 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.listenUsingRfcommWithServiceRecord("BarcodeScannerForSGST", UUID_BLUETOOTH); /* * The UUID is also included in the SDP entry and will be the basis for the connection * agreement with the client device. That is, when the client attempts to connect with this device, * it will carry a UUID that uniquely identifies the service with which it wants to connect. * These UUIDs must match in order for the connection to be accepted (in the next step) */ } catch (IOException e) { } mmServerSocket = tmp; } public void run() { BluetoothSocket socket = null; // Keep listening until exception occurs or a socket is returned while (true) { try { socket = mmServerSocket.accept(); try { // If a connection was accepted if (socket != null) { // Do work to manage the connection (in a separate thread) InputStream mmInStream = null; // Get the input and output streams, using temp objects because // member streams are final mmInStream = socket.getInputStream(); byte[] buffer = new byte[1024]; // buffer store for the stream int bytes; // bytes returned from read() // Keep listening to the InputStream until an exception occurs // Read from the InputStream bytes = mmInStream.read(buffer); if (bytes &gt; 0) { // Send the obtained bytes to the UI activity String readMessage = new String(buffer, 0, bytes); //doMainUIOp(BARCODE_READ, readMessage); if (readMessage.length() &gt; 0 &amp;&amp; !etMlfb.isEnabled()) //Se sono nella parte di picking new ServerWorker().execute(new Object[] {LEGGI_SPED, readMessage}); } socket.close(); } } catch (Exception ex) { } } catch (IOException e) { break; } } } /** * Will cancel the listening socket, and cause the thread to finish */ public void cancel() { try { mmServerSocket.close(); } catch (IOException e) { } } } </code></pre> <p>Thanks</p>
    singulars
    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.
 

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