• notice
  • Congratulations on the launch of the Sought Tech site

How to get the Mac address of an AndroidStudio app

I am use Java (Android studio) creates Android apps on Android, so I want to get the Mac address. So my question is how to find the Mac address? Mac addresses are unique to each user.User will download the app and then he should show the mac address so that he can activate the device from the website using the same mac address. So I just want to get the MAC address, which is unique for each user.

uj5u.com enthusiastic netizens replied:

First step:Add permissions.in Manifest.xmlAdd the following line to the file

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Step 2:Create a method to get the MAC address

public String getMacAddress(){
        try{
            List<NetworkInterface> networkInterfaceList=Collections.list(NetworkInterface.getNetworkInterfaces());
            String stringMac="";
            for(NetworkInterface networkInterface : networkInterfaceList){
                if(networkInterface.getName().equalsIgnoreCase("wlon0"));
                {
                    for(int i=0;i <networkInterface.getHardwareAddress().length; i){
                        String stringMacByte=Integer.toHexString(networkInterface.getHardwareAddress()[i]& 0xFF);
                        if(stringMacByte.length()==1){
                            stringMacByte="0" stringMacByte;
                        }
                        stringMac=stringMacByte.toUpperCase() ":";
                    } break;
                }
            }
            return stringMac;
        }catch (SocketException e)
        {
            e.printStackTrace();
        }
        return "0";
    }

Step 3:Call the method to obtain the MAC address

String mobile_mac_addres = getMacAddress(); //call the method that return mac address 
Log.d("MyMacIS",mobile_mac_address); //this prints the MAC Address

uj5u.com enthusiastic netizens replied:

Use this code programmatically to get macAddress

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    WifiInfo wInfo = wifiManager.getConnectionInfo();
    String macAddress = wInfo.getMacAddress();

Tags

Technical otaku

Sought technology together

Related Topic

0 Comments

Leave a Reply

+