私のプロジェクトでは、バーコードスキャナSymbol CS3070を使用してバーコードを読み取る必要があります。すなわち、私はアンドロイドデバイスとバーコードスキャナの間の接続を確立する必要がありますブルートゥース。バーコードリーダーから値を読み取る方法と、通信をセットアップする方法を教えてもらえますか?私はすでにBluetooth Developer Guideを読んでおり、Bluetoothキーボードエミュレーション(HID)モードでバーコードリーダーを使用したくない(ソフトキーボードとバーコードリーダーを使って入力できるテキストビューがいくつかあり、フォーカスを制御できない)ブルートゥースバーコードスキャナからデータを読み取る方法Symbol CS3070からAndroidデバイス
私がリーダーで、私はちょうど私のデバイスとするとき、私はそれが自動的にデータを送信するデバイスをペアリングし、接続を受け
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 > 0) {
// Send the obtained bytes to the UI activity
String readMessage = new String(buffer, 0, bytes);
//doMainUIOp(BARCODE_READ, readMessage);
if (readMessage.length() > 0 && !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) { }
}
}
おかげ
私のアプリケーションに同じ機能が必要です。このタスクに関連する有用な情報があれば教えてください。 –
私もこれを達成しようとしています。あなたが解決策を見つけたら教えてください。ありがとうございました。 –
今のところ解決策はありません... – Android84