I want to access MAC Address of phone using Wifi. but somehow I could not get it right. I have written following code.
context=this;
        setContentView(R.layout.activity_main);
        try{    
            WifiManager wifi=(WifiManager)this.context.getSystemService(context.WIFI_SERVICE);
            wifi.setWifiEnabled(true);
            WifiInfo info=wifi.getConnectionInfo();
            String address=info.getMacAddress();
            if(address==null){
                Toast.makeText(context, "Null", Toast.LENGTH_LONG).show();
            }
            else{
                new AsyncClass(MainActivity.this,address).execute();
            }
        }catch(Exception e){
            Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
        }
When I run this on my phone, it give me error that "Unfortunately Application Stopped" When I run this program on Imulator, it always gives address is Null. Please help me to get rid of it. Thanks in advance.
My Manifest file is as below:
<uses-permission
        android:required="true"
        android:name="android.permission.ACCESS_WIFI_STATE"/>
    <uses-permission
        android:required="true"
        android:name="android.permission.CHANGE_WIFI_STATE"/>
    <uses-permission
        android:required="true"
        android:name="android.permission.INTERNET"/>
 
     
     
     
     
     
    