2013-10-11 7 views
5

में ब्लूटूथ से जुड़े उपकरण का MAC पता पाने के लिए मैं एंड्रॉयड में ब्लूटूथ के माध्यम से एक छवि भेज रहा हूँ और करने के लिए जो छवि भेजा जा रहा है डिवाइस के मैक पता लाने के लिए चाहते हैं।कैसे एंड्रॉयड

कृपया मेरे कोड के नीचे मिला।

private void bluetoothadd(){ 
    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); 
    if (mBluetoothAdapter == null) { 
     // Device does not support Bluetooth 

     Log.e("Bluetooth ","not found"); 
    } 

    if (!mBluetoothAdapter.isEnabled()) { 
     Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
     startActivity(enableBtIntent); 

     Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); 
     // If there are paired devices 
     if (pairedDevices.size() > 0) { 
      // Loop through paired devices 
      for (BluetoothDevice device : pairedDevices) { 


       Log.e("Mac Addressess","are: "+mBluetoothAdapter.getRemoteDevice(device.getAddress())); 
      } 
      } 
     } 

} 

मुझे सभी जोड़े गए डिवाइस के मैक पते मिल रहे हैं। मैं एक डिवाइस का मैक पता चाहता हूं कि केवल किस डेटा को प्रसारित किया जा रहा हो।

+1

आप पते, जब अन्य डिवाइस उपयोगकर्ता के उपकरण से जुड़ा है, या यहाँ तक कि इससे पहले कि कनेक्शन स्थापित हो जाने (डिस्कवरी चरण) लगाना चाहते हैं .. ??? – Shiva

+0

मुझे कनेक्ट होने पर किसी अन्य डिवाइस का पता चाहिए और मैं मैक पता प्राप्त कर सकता हूं कि डेटा किस डिवाइस पर भेजा जा रहा है। –

+0

जांच निम्न लिंक http://stackoverflow.com/questions/10795424/how-to-get-the-bluetooth-devices-as-a-list http://stackoverflow.com/questions/16471204/खोज-ब्लूटूथ-डिवाइस-सूचीदृश्य-नहीं-नहीं-अपडेट-अपडेट –

उत्तर

-3

यह कोशिश करो।

WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE); 
WifiInfo info = manager.getConnectionInfo(); 
String address = info.getMacAddress(); 
+0

नहीं, यह वाईफ़ाई है। हालांकि मैक पते शब्द का उपयोग आमतौर पर वाईफाई से जुड़ा होता है, इसका उपयोग ब्लूटूथ बीडी_एडीडीआर के लिए भी किया जा सकता है। – Tom

+0

मैक पता केवल वाई-फाई मॉड्यूल के साथ उपलब्ध है! – alezhka

0

तो, ऐसा लगता है जैसे आप किसी डिवाइस के bd_addr/mac को प्राप्त करना चाहते हैं जिसके साथ आपका कनेक्शन है? तो ध्यान दें BluetoothSocket वर्ग एक सदस्य 'getRemoteDevice' है, जो एक BluetoothDevice उदाहरण डिवाइस आप से जुड़े हैं, जिस पर आप मैक पाने के लिए getAddress() कॉल कर सकते हैं का प्रतिनिधित्व करने देता है।

या आप ACTION_ACL_CONNECTED जो 'EXTRA_DEVICE' है कि आप एक BluetoothDevice को बढ़ावा मिलेगा शामिल के लिए रजिस्टर कर सकते हैं।

1

जब आशय रिमोट डिवाइस से कनेक्ट करने के निकाल दिया जाता है और डिवाइस सफलतापूर्वक डिवाइस पता स्थापित है झंडा EXTRA_DEVICE_ADDRESS के साथ अतिरिक्त डेटा के रूप में दिया जाता है।

आप कनेक्शन के लिए जाँच करें और स्थापित यह

if (!mBluetoothAdapter.isEnabled()) { 
      Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
      startActivityForResult(enableIntent, REQUEST_ENABLE_BT); 

आप इस

public void onActivityResult(int requestCode, int resultCode, Intent data) { 

     switch (requestCode) { 
     case REQUEST_CONNECT_DEVICE: 
      // When DeviceListActivity returns with a device to connect 
      if (resultCode == Activity.RESULT_OK) { 
       // Get the device MAC address 
       String add = data.getExtras() 
            .getString(DeviceListActivity.EXTRA_DEVICE_ADDRESS); 
       address= add.toString(); 

       // Get the BluetoothDevice object 
       BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); 

      } 
      break; 
} 
} 

यह चाल ब्लूटूथ में प्रयोग किया जाता है की तरह पता लगाने के लिए onActivityResult समारोह पर में गतिविधि देख सकते हैं कर सकते हैं चैट नमूना आवेदन आप एसडीके के उदाहरण फ़ोल्डर

3

उपयोग इस में पा सकते हैं:

BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); 
-1

मेरे लिए यह काम:

String macAddress = android.provider.Settings.Secure.getString(mContext.getContentResolver(), "bluetooth_address");