मैं एंड्रॉइड पर सभी जुड़े ब्लूटूथ डिवाइसों को कैसे सूचीबद्ध कर सकता हूं?जुड़े ब्लूटूथ डिवाइस सूचीबद्ध?
धन्यवाद!
मैं एंड्रॉइड पर सभी जुड़े ब्लूटूथ डिवाइसों को कैसे सूचीबद्ध कर सकता हूं?जुड़े ब्लूटूथ डिवाइस सूचीबद्ध?
धन्यवाद!
कृपया this class ऑनलाइन विश्लेषण करें।
यहां आप पाएंगे कि सभी जुड़े (जोड़े गए) ब्लूटूथ डिवाइस कैसे खोजें।
हाय Desiderio, जैसा कि मैंने कहा था कि मैं कनेक्टेड (सक्रिय) डिवाइस सूचीबद्ध करना चाहता हूं, न कि जोड़े/भरोसेमंद। – Shatazone
ब्रॉडकास्ट ACTION_ACL_CONNECTED की निगरानी के बारे में क्या? – Zelimir
मैं उस कक्षा को कैसे डाउनलोड कर सकता हूं? मुझे लगता है कि यह मेरी समस्या पर मेरी मदद करेगा। – Sonhja
खैर यहाँ कदम हैं:
सबसे पहले, आप उपकरणों
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
की खोज करने के लिए यह एक प्रसारण reciver रजिस्टर आशय शुरू:
registerReceiver(mReceiver, filter);
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();
}
}
और सूची स्वचालित रूप से नए उपकरण का अन्वेषण पर भरे जाएंगे।
एक गायब है}; कोड के अंत में। मैं खुद को संपादित नहीं कर सकता क्योंकि इसे 6 वर्ण परिवर्तन होना चाहिए, और यह केवल गायब है 2. –
एंड्रॉइड सिस्टम आपको सभी "वर्तमान में जुड़े" उपकरणों के लिए क्वेरी नहीं करने देता है। हालांकि, आप युग्मित उपकरणों के लिए पूछ सकते हैं। वर्तमान में कनेक्ट किए गए ट्रैक को ट्रैक करने के लिए आपको अपने आवेदन राज्यों को अपडेट करने के लिए STATE_BONDED ईवेंट के साथ ACTION_ACL_ {कनेक्ट किए गए | अस्वीकृत} ईवेंट के साथ एक प्रसारण रिसीवर का उपयोग करने की आवश्यकता होगी।
एपीआई 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;
}
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);
}
};
आप इस के लिए समाधान मिल गया है:
यहाँ कोड उदाहरण है कि किसी भी एपीआई डिवाइस पर काम करेगा। मैं वही खोज रहा हूं, कृपया उत्तर दें। –