2

I am trying to obtain the MAC Address of the Android Device on which I am executing my Qt android app code. It is giving the correct MAC Id when I am running it on Windows Desktop but on Android Device it is showing the MAC address as 00:00:00:00:00:00. Android Device is connected via USB to the desktop. Is there any way to obtain the MAC ID of the device using Qt Programming? Here is my code snippet:-

QNetworkInterface networkInterface;
QString m_strHWAddress1;
QList<QNetworkInterface> list1=QNetworkInterface::allInterfaces();

foreach(networkInterface, list1)
{
    if(networkInterface.flags().testFlag(QNetworkInterface::IsUp) && !networkInterface.flags().testFlag(QNetworkInterface::IsLoopBack))
    {
        m_strHWAddress1 = networkInterface.hardwareAddress();
    }

    qDebug()<<"hadd:  "<<m_strHWAddress1.toStdString().c_str();
}

Thanks in Advance!!

AmarSneh
  • 103
  • 1
  • 6
  • Perhaps: http://stackoverflow.com/a/7616111/168175 is relevant? – Flexo Jul 23 '14 at 20:45
  • @Flexo.. I have tried that. But it gives the correct MAC address when I run the app on Windows PC. But gives 00:00:00:00:00:00 when I run it on my android device. – AmarSneh Jul 24 '14 at 07:03
  • My guess (untested) is that non-rooted Android OSes block applications from seeing the real MAC address to prevent apps from uniquely identifying the device, the same way Apple hides the true UDID from apps in iOS. – nobody Jul 24 '14 at 19:49

1 Answers1

0

Faced the same issue.

Fixed it by implementing following steps:

  1. Added permission for android.permission.ACCESS_WIFI_STATE in AndroidManifest.xml file
  2. Connected my android device to a wifi hotspot (so that it has an IP address).
Praveen Kumar
  • 483
  • 1
  • 5
  • 12