2010-10-14 31 views
12

मैं एंड्रॉइड पर सभी जुड़े ब्लूटूथ डिवाइसों को कैसे सूचीबद्ध कर सकता हूं?जुड़े ब्लूटूथ डिवाइस सूचीबद्ध?

धन्यवाद!

+0

आप इस के लिए समाधान मिल गया है:

यहाँ कोड उदाहरण है कि किसी भी एपीआई डिवाइस पर काम करेगा। मैं वही खोज रहा हूं, कृपया उत्तर दें। –

उत्तर

-1

कृपया this class ऑनलाइन विश्लेषण करें।

यहां आप पाएंगे कि सभी जुड़े (जोड़े गए) ब्लूटूथ डिवाइस कैसे खोजें।

+0

हाय Desiderio, जैसा कि मैंने कहा था कि मैं कनेक्टेड (सक्रिय) डिवाइस सूचीबद्ध करना चाहता हूं, न कि जोड़े/भरोसेमंद। – Shatazone

+0

ब्रॉडकास्ट ACTION_ACL_CONNECTED की निगरानी के बारे में क्या? – Zelimir

+0

मैं उस कक्षा को कैसे डाउनलोड कर सकता हूं? मुझे लगता है कि यह मेरी समस्या पर मेरी मदद करेगा। – Sonhja

1

खैर यहाँ कदम हैं:

  1. सबसे पहले, आप उपकरणों

    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);

  2. की खोज करने के लिए यह एक प्रसारण reciver रजिस्टर आशय शुरू:

    registerReceiver(mReceiver, filter);

  3. mReceiver की परिभाषा पर:

    private final BroadcastReceiver mReceiver = new BroadcastReceiver() { 
        public void onReceive(Context context, Intent intent) { 
        String action = intent.getAction(); 
        // When discovery finds a device 
        if (BluetoothDevice.ACTION_FOUND.equals(action)) { 
         // Get the BluetoothDevice object from the Intent 
         BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); 
         // Add the name and address to an array adapter to show in a ListView 
         arrayadapter.add(device.getName())//arrayadapter is of type ArrayAdapter<String> 
         lv.setAdapter(arrayadapter); //lv is the list view 
         arrayadapter.notifyDataSetChanged(); 
        } 
    } 
    

और सूची स्वचालित रूप से नए उपकरण का अन्वेषण पर भरे जाएंगे।

+0

एक गायब है}; कोड के अंत में। मैं खुद को संपादित नहीं कर सकता क्योंकि इसे 6 वर्ण परिवर्तन होना चाहिए, और यह केवल गायब है 2. –

0

एंड्रॉइड सिस्टम आपको सभी "वर्तमान में जुड़े" उपकरणों के लिए क्वेरी नहीं करने देता है। हालांकि, आप युग्मित उपकरणों के लिए पूछ सकते हैं। वर्तमान में कनेक्ट किए गए ट्रैक को ट्रैक करने के लिए आपको अपने आवेदन राज्यों को अपडेट करने के लिए STATE_BONDED ईवेंट के साथ ACTION_ACL_ {कनेक्ट किए गए | अस्वीकृत} ईवेंट के साथ एक प्रसारण रिसीवर का उपयोग करने की आवश्यकता होगी।

2

एपीआई 14 (आइस क्रीम) के रूप में, Android सहित एक कुछ नए BluetoothAdapter तरीकों है:

public int getProfileConnectionState (int profile)

जहां प्रोफ़ाइल, HEALTH, HEADSET, A2DP

चेक प्रतिक्रिया में से एक है अगर यह STATE_DISCONNECTED नहीं है क्या आप जानते हैं आपके पास एक लाइव कनेक्शन है।

BluetoothAdapter mAdapter; 

/** 
* Check if a headset type device is currently connected. 
* 
* Always returns false prior to API 14 
* 
* @return true if connected 
*/ 
public boolean isVoiceConnected() { 
    boolean retval = false; 
    try { 
     Method method = mAdapter.getClass().getMethod("getProfileConnectionState", int.class); 
     // retval = mAdapter.getProfileConnectionState(android.bluetooth.BluetoothProfile.HEADSET) != android.bluetooth.BluetoothProfile.STATE_DISCONNECTED; 
     retval = (Integer)method.invoke(mAdapter, 1) != 0; 
    } catch (Exception exc) { 
     // nothing to do 
    } 
    return retval; 
} 
+0

हाय योसी, क्या आपके पास इसके लिए कुछ कोड है? यह बहुत अच्छा होगा :) –

+0

अगर मेरे पास ब्लूटूथ है तो भी मुझे हमेशा सही कर रहा है, भले ही मैं – JesusS

+0

सिम्युलेटर या वास्तविक डिवाइस से कनेक्ट न हो? कौन सा डिवाइस और एंड्रॉइड संस्करण? – Yossi

0
public void checkConnected() 
{ 
    // true == headset connected && connected headset is support hands free 
    int state = BluetoothAdapter.getDefaultAdapter().getProfileConnectionState(BluetoothProfile.HEADSET); 
    if (state != BluetoothProfile.STATE_CONNECTED) 
    return; 

    try 
    { 
    BluetoothAdapter.getDefaultAdapter().getProfileProxy(_context, serviceListener, BluetoothProfile.HEADSET); 
    } 
    catch (Exception e) 
    { 
    e.printStackTrace(); 
    } 
} 

private ServiceListener serviceListener = new ServiceListener() 
{ 
    @Override 
    public void onServiceDisconnected(int profile) 
    { 

    } 

    @Override 
    public void onServiceConnected(int profile, BluetoothProfile proxy) 
    { 
    for (BluetoothDevice device : proxy.getConnectedDevices()) 
    { 
     Log.i("onServiceConnected", "|" + device.getName() + " | " + device.getAddress() + " | " + proxy.getConnectionState(device) + "(connected = " 
      + BluetoothProfile.STATE_CONNECTED + ")"); 
    } 

    BluetoothAdapter.getDefaultAdapter().closeProfileProxy(profile, proxy); 
    } 
}; 
संबंधित मुद्दे