2016-01-21 153 views
5

好發送藍牙字符串,所以我有(我希望)一個bluetooth.java類就送我的琴絃。但是每當我試圖發送命令我破碎的祝酒詞只是表示說沒了。我錯過了一些重要的東西?我只有這兩個功能在那裏..在android系統

void openBT() throws IOException { 

    UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); 
    try { 
     mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid); 
    } catch (IOException e) { 
     Toast.makeText(getApplicationContext(), "Unable to create socket", Toast.LENGTH_LONG).show(); 
    } 
    try { 
     mmSocket.connect(); 
    } catch (IOException e) { 
     Toast.makeText(getApplicationContext(), "Unable to connect to socket", Toast.LENGTH_LONG).show(); 
    } 
    mmOutputStream = mmSocket.getOutputStream(); 
    mmInputStream = mmSocket.getInputStream(); 
} 

void sendData2() throws IOException { 
    if (BtCommand == "0"){ 
     msg = "Fan2 Off"; 
    } 
    if (BtCommand == "1"){ 
     msg = "Fan2 On"; 
    } 

    mmOutputStream.write(msg.getBytes()); 
} 

,這些都是唯一的東西,我設置

BluetoothSocket mmSocket; 
BluetoothDevice mmDevice; 
String BtCommand; 
OutputStream mmOutputStream; 
InputStream mmInputStream 

我相信這是一個失敗的openBT功能,我配對的設備精細。

回答

0

你確定使用選定的UUID嗎?

List of UUIDs

或者,嘗試返工你的代碼。我使用2個線程(1連接和第二連接和通信)

+0

我不知道沒有?我認爲這UUID對應於所有的藍牙設備,當我試了一下,我2個Android手機(SONY Z1和SONY Z5) –

+0

之間嘗試,我使用00001112-0000-1000-8000-00805f9b34fb – Majkl

+0

我會嘗試一下,謝謝。 –