How to find MAC address of an Android device programmatically
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String macAddress = wInfo.getMacAddress();
Also, add below permission in your manifest file
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Please refer to Android 6.0 Changes.
To provide users with greater data protection, starting in this release, Android removes programmatic access to the device’s local hardware identifier for apps using the Wi-Fi and Bluetooth APIs. The WifiInfo.getMacAddress() and the BluetoothAdapter.getAddress() methods now return a constant value of 02:00:00:00:00:00.
To access the hardware identifiers of nearby external devices via Bluetooth and Wi-Fi scans, your app must now have the ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION permissions.
Get the MAC address of bluetooth adapter in Android
What Youssif Saeed said in the other answer was correct. Android won't let us get the MAC address anymore.
Brief description about what I want:
Let's say I have a phone with MAC Address X, and I have another nearby device with MAC address B. When the two devices are nearby each other. I was able to get the MAC address of the other device using BluetoothDevice and getAddress() method from ScanResult.getDevice(). So what I still need is to catch my own device MAC address so that in the backend I save each user with his MAC address, and when I catch it in bluetooth, I know who's nearby me
Here's the workaround I've done in order to send some data between near devices.
I found something called Nearby Messages API. It is available for Android and iOS and very easy to implement. Now I'm able to catch near devices with my application installed on them, and send a unique Id generated by the application to identify the user.
Related Topics
Manually Put Files to Android Emulator Sd Card
How to Solve the Install_Failed_Dexopt Error
How to Crop an Image in Android
How to Downgrade Android Emulator
How to Use Adb to Send Touch Events to Device Using Sendevent Command
Androidx:Appcompat I:Art Error Android.View.View$Onunhandledkeyeventlistener
Why Use Android Picasso Library to Download Images
How to Force Action Bar Overflow Icon to Show
How to Dynamically Remove Items from Listview on a Button Click
Detecting When User Has Dismissed the Soft Keyboard
Emulator in Android Studio Doesn't Start
Setonitemclicklistener on Custom Listview
Android Gradle Apache Httpclient Does Not Exist
Android: Mediaplayer Setvolume Function