5
我跟進了this問題,但所有提到的解決方案都不適用於我。在Android中通過藍牙發送文件時出錯?
我正在製作類似於彩虹應用程序的應用程序。此應用程序將被安裝在具有要發送到其他device.The應用程序的所有接觸裝置將要被安裝的僅在一個device.I是能夠通過此片的代碼
連接到所述遠程設備// BluetoothConnector(Complete Code)
Class<?> clazz = tmp.getRemoteDevice().getClass();
Class<?>[] paramTypes = new Class<?>[] {Integer.TYPE};
Method m = clazz.getMethod("createRfcommSocket", paramTypes);
Object[] params = new Object[] {Integer.valueOf(1)};
fallbackSocket = (BluetoothSocket) m.invoke(tmp.getRemoteDevice(), params);
配對請求並連接完成後,我試圖通過的OutputStream通過這一段代碼將數據發送到其它設備。
//輸出流代碼(Complete code)
public void write(byte[] buffer) {
try {
Log.i(TAG, "write");
mmOutStream.write(buffer);
} catch (IOException e) {
Log.e(TAG, "Exception during write", e);
}
,但我不能夠儘快發送數據mmOutStream.write(緩衝);被稱爲它提供了以下錯誤
//錯誤日誌(Complete Log)
09-21 16:21:52.829 6262-6262/com.example.aadi.myapplication D/BT_app﹕ connection_done
09-21 16:21:52.829 6262-6871/com.example.aadi.myapplication I/BT_app﹕ BEGIN mConnectedThread
09-21 16:21:52.829 6262-6871/com.example.aadi.myapplication I/BT_app﹕ write
09-21 16:21:52.829 6262-6262/com.example.aadi.myapplication D/BT_app﹕ msg write :[[email protected]
09-21 16:22:50.149 6262-6823/com.example.aadi.myapplication W/BluetoothAdapter﹕ getBluetoothService() called with no BluetoothManagerCallback
09-21 16:22:50.159 6262-6823/com.example.aadi.myapplication D/BluetoothSocket﹕ connect(), SocketState: INIT, mPfd: {ParcelFileDescriptor: FileDescriptor[81]}
09-21 16:22:50.679 6262-6823/com.example.aadi.myapplication W/BT_app﹕ Fallback failed. Cancelling.
java.io.IOException: read failed, socket might closed or timeout, read ret: -1
at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:505)
at android.bluetooth.BluetoothSocket.waitSocketSignal(BluetoothSocket.java:482)
at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:324)
at com.example.aadi.myapplication.BluetoothConnector$FallbackBluetoothSocket.connect(BluetoothConnector.java:202)
at com.example.aadi.myapplication.BluetoothConnector.connect(BluetoothConnector.java:64)
at com.example.aadi.myapplication.BluetoothService$ConnectThread.run(BluetoothService.java:218)
09-21 16:22:50.679 6262-6823/com.example.aadi.myapplication I/BT_app﹕ Attempting to connect to Protocol: 0000112f-0000-1000-8000-00805f9b34fb
請告訴我在上面的代碼中我做錯了什麼。 是否可以通過藍牙傳輸文件而無需實現服務器端代碼?
我回答你的最後一個問題,是的,它可以通過藍牙傳輸文件無需服務器端 – 2014-09-21 11:08:35
@NadirB任何解釋答案將有幫助 – 2014-09-24 08:19:06
您的BlootothDevice是否支持身份驗證?源文件中的文檔表明,您只能使用'createRfcommSocket'和遠程設備,它支持認證。在這種情況下,它說你應該使用'createInsecureRfcommSocket'。 – Soana 2014-09-24 09:31:37