2014-02-12 59 views
0

我正在將串行藍牙設備連接到我的Android應用程序。它運作良好,但只有當設備上..設備未連接時Android藍牙崩潰

當我的藍牙設備(「Gps_3.3v_4800」)設備關閉我的應用程序崩潰時,它啓動。有沒有辦法看它是否上?或者無論如何,以防止我的應用程序崩潰。

for (BluetoothDevice device : pairedDevices) { 
       btDevice[i] = device.getName(); 
       System.out.println(device.getName() + device.getAddress() + " \n"); 

       // Connect to my device 
       if(device.getName().equalsIgnoreCase("Gps_3.3v_4800")) { 
         Thread ct = new ConnectThread(device, mBluetoothAdapter); 
         isct = new ConnectedThread(((ConnectThread) ct).getSocket()); 
         ((ConnectedThread)isct).setJavascript(javascr); 
         ((ConnectedThread)isct).write("hallo"); 
         isct.start(); 
       } 
} 

我當設備上沒有錯誤:

致命信號11(SIGSEGV)在0x00000008(代碼= 1),螺紋3928(線程4174)

更新 現在我得到一個空指針 (java.lang.RuntimeException:無法啓動活動ComponentInfo {com.example.hellobt/com.example.hellobt.MainActivity}: 顯示java.lang.NullPointerException) 試圖阻止時,它不會連接線..

+2

它拋出了什麼異常?將它圍繞在try/catch塊中,並正確處理異常 –

+0

您是否使用過藍牙許可:<使用權限android:name =「android.permission.BLUETOOTH」/> – Umitk

+0

是的,我也是BLUETOOTH_ADMIN。我認爲那不是問題,因爲它可以與設備連接。 –

回答

0

解決了檢查問題:

如果(mmSocket.isConnected())

我覺得這是隻有手機與其他設備連接時出現問題。但對我來說沒問題。

謝謝大家。