How to Get the MAC of an Android Device Programmatically?
Last Updated :
15 Mar, 2024
MAC stands for Media Access Control. The MAC address is also known as the Equipment Id Number. This MAC Address is provided by the Network Interface Card. In this article, we will see step by step from creating a new empty project to How to make an android app to display MAC Address using Java.
Note: All the hardware access has been removed after Android 11, so if you want to follow these steps then you have to choose the lower version of Android 11.
Step by Step Implementation
Step 1: Open an 'Android Studio' and click on New Project.

Step 2: Select Empty Activity.

Step 3: Select Java as the language for your Android app and give it any name you want.

Step 4: Add the following Permissions in the AndroidManifest.xml file.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name = "android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.LOCAL_MAC_ADDRESS" />
AndroidManifest.xml file will look like this
XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.app.getmymac">
<!-- Permissions -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name = "android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.LOCAL_MAC_ADDRESS" />
<!-- Permissions -->
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.GetMyMAC"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Step 5: Make a simple design to show MAC Address.
Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file.
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="You Device's MAC Address "
android:textSize="20sp"
android:textColor="@color/black"
android:layout_centerHorizontal="true"
android:layout_above="@id/mac_id"
/>
<TextView
android:id="@+id/mac_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="MAC ID"
android:textSize="22sp"
/>
</RelativeLayout>
The above code makes the UI like the below.

Step 6: Now we are in the final phase of the project, Import WifiInfo and WifiManager classes using the below lines of code in MainActivity.java Â
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
Step 7: Go to the MainActivity.java file and refer to the following code. Below is the code for the MainActivity.java file.
Java
import android.annotation.SuppressLint;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
TextView macIdTV;
@SuppressLint("MissingPermission")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
macIdTV = findViewById(R.id.mac_id);
WifiManager wifiMgr = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
final String MAC_ADDRESS = wifiInfo.getMacAddress();
macIdTV.setText(MAC_ADDRESS);
macIdTV.setVisibility(View.VISIBLE);
}
}
Now all are set, just run your app and you will be able to see the MAC address of your Android device. Hooray!
Output:
Similar Reads
How to Get the Device's IMEI and ESN Programmatically in Android? Many times while building Android Applications we require a unique identifier to identify the specific mobile users. For identifying that user we use a unique address or identity. For generating that unique identity we can use the android device id. In this article, we will take a look at How to get
4 min read
How to Fetch Device ID in Android Programmatically? The android Device ID is a unique code, string combinations of alphabets and numbers, given to every manufactured android device. This code is used to identify and track each android device present in the world. In Android, the Device ID is typically related to the Google Play Services and is most c
3 min read
How to Find the Screen Resolution of a Device Programmatically in Android? Screen Resolution refers to the number of pixels on display. A higher resolution means more pixels and more pixels provide the ability to display more visual information. This entity is widely used in applications related to the broadcasting of real-time visuals such as live video, gaming, etc for o
3 min read
How to Get Current Default Language of Android Device Programmatically? Smartphones seem to be predicting and showing us results from what we think in our minds. If you think of traveling, you shall soon expect something related to it in your device's feed. This is the next level of technology, where data helps in developing businesses. The software collects personal da
2 min read
How to Detect Tablet or Phone in Android Programmatically? A Mobile is a portable electronic device that allows you to make calls, send messages, and access the internet, among other functions. A tablet is a mobile computing device with a touchscreen display and typically a larger screen size than a smartphone. Both devices are designed to be portable and a
3 min read
How to Get RAM Memory in Android Programmatically? RAM (Random Access Memory) of a device is a system that is used to store data or information for immediate use by any application that runs on the device. Every electronic device that runs a program as a part of its application has some amount of RAM associated with it. Mobile devices nowadays come
3 min read
How to Display the List of Sensors Present in an Android Device Programmatically? All Android devices produced worldwide come with built-in sensors that measure motion, orientation, and various environmental conditions. These sensors generally facilitate Android architecture by providing the data from the sensor for various applications. For example, a temperature sensor provides
3 min read
How to Check Airplane Mode State in Android Programmatically? Airplane Mode is often seen in action during flights, avoiding calls, or rebooting the network on mobiles, tablets, and laptops. Airplane mode is a standalone mode where the device turns down the radio communications. These may include Wifi, GPS, Telephone Network, Hotspot depending upon the year of
3 min read
How to Get the Device's IMEI/ESN Programmatically in Android using Jetpack Compose? Android applications many times require the unique identity of the user while developing applications. This unique identity is used to identify the user of the application. Many android apps use the IMEI number as the unique identity of each user. In this article, we will take a look at How to get D
3 min read
How to Obtain the Connection Information Programmatically in Android? Sometimes it becomes challenging to find the network-related details, especially the device's IP address, which could be needed to grant unique preferences through the modem software. Because of the variance in the information shown to the user across multiple Android devices (Samsung, Mi, Lava), we
4 min read