2012-04-25 18 views
6

मैं काम क्लाइंट-सर्वर ब्लूटूथ समझने की कोशिश कर रहा हूँ। जहां एंड्रॉइड क्लाइंट है। पीसी सर्वर है।रिमोट ब्लूटूथ

मैं code पाया। यह काम एक सैमसंग गैलेक्सी 10.1 (Android 3.2), लेकिन एक सैमसंग गैलेक्सी एस (एंड्रॉयड 2.3.3) काम नहीं करता ans HTC जंगल की आग एस (Android 2.2)।

MY_UUID = UUID.fromString("04c6093b-0000-1000-8000-00805f9b34fb"); 

04-25 18:32:37.023: D/BluetoothCommandService(13665): setState() 1 -> 2 
04-25 18:32:37.033: I/BluetoothCommandService(13665): BEGIN mConnectThread 
04-25 18:32:37.063: E/BluetoothService.cpp(102): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session) 
04-25 18:32:37.103: E/BluetoothCommandService(13665): Unable to start Service Discovery 
04-25 18:32:37.103: E/BluetoothCommandService(13665): java.io.IOException: Unable to start Service Discovery 
04-25 18:32:37.103: E/BluetoothCommandService(13665): at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:367) 
04-25 18:32:37.103: E/BluetoothCommandService(13665): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:201) 
04-25 18:32:37.103: E/BluetoothCommandService(13665): at com.luugiathuy.apps.remotebluetooth.BluetoothCommandService$ConnectThread.run(BluetoothCommandService.java:258) 
04-25 18:32:37.103: D/BluetoothCommandService(13665): setState() 2 -> 1 

उत्तर

6

आपकी डिवाइस सेवा खोज के लिए विफल रहता है (मुझे ऐसा लगता है)।

  1. मैं L2CAP/HID प्रोफ़ाइल के लिए जहां विशेष रूप से कई सैमसंग उपकरणों और HTC उपकरणों के साथ बीटी मुद्दों लेकिन उन के बारे में पढ़ा है। Soln: आप एसपीपी या RFCOMM इस्तेमाल कर सकते हैं अगर आप L2CAP

  2. उपयोग कर रहे हैं आप ऊपर समाधान में उल्लेख किया है में से एक का उपयोग कर रहे हैं तो मानक UUID के साथ उपयोग करने का प्रयास

एसपीपी 00001101-0000-1000- 8000-00805F9B34FB

RFCOMM 00000003-0000-1000-8000-00805F9B34FB

संपादित

वैकल्पिक रूप से आप प्रतिबिंब का उपयोग कर नीचे दी गई विधि की तरह अपने गर्तिका कनेक्शन कुछ पाने की कोशिश कर सकते

private static BluetoothSocket createBluetoothSocket(
     int type, int fd, boolean auth, boolean encrypt, String address, int port){ 
    try { 
     Constructor<BluetoothSocket> constructor = BluetoothSocket.class.getDeclaredConstructor(
       int.class, int.class,boolean.class,boolean.class,String.class, int.class); 
     constructor.setAccessible(true); 
     BluetoothSocket clientSocket = (BluetoothSocket) 
      constructor.newInstance(type,fd,auth,encrypt,address,port); 
     return clientSocket; 
    }catch (Exception e) { return null; } 
} 
+0

काम नहीं करता है, और अधिक विकल्प हो सकता है? – alezhka

+0

यह एक एंड्रॉइड 2.3 काम कर रहा है, लेकिन 2.2 – alezhka

+0

नहीं क्या आपको कोई नई त्रुटियां या एक ही समस्या है ... और क्या यह आपके सभी डिवाइसों के साथ काम करता है –

2

आज़माएं:

static int sdk = Integer.parseInt(Build.VERSION.SDK); 

private static final UUID MY_UUID = 
    UUID.fromString((sdk<=8||sdk>=11)?"04c6093b-0000-1000-8000-00805f9b34fb":"00001101-0000-1000-8000-00805F9B34FB"); 

यह मेरे लिए काम किया है :)
पर 2.1 परीक्षण किया गया - 3.3 और 4.0.4 एंड्रॉइड संस्करण।

+0

यह मेरे लिए भी काम किया है। लेकिन क्यों?? – Hugo

+0

मुझे लगता है कि ऐसा इसलिए है क्योंकि नए स्मार्टफोन पुराने ब्लूटूथ प्रोटोकॉल का उपयोग पुराने लोगों की तुलना में नहीं करते हैं और इसलिए उनका यूयूआईडी भी बदल गया है। – nonozor

संबंधित मुद्दे