I have two classes: one of them is the activity class, and the other is inactive. And I call the method that is inside the non-activity class to return the mac address.
activity class:
public class Control extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
deneme d = new deneme(this);
String x = d.macadress();
Toast.makeText(getApplicationContext(), x, Toast.LENGTH_LONG).show();
}}
and inactivity class:
public class deneme {
Context mcontext ;
WifiManager wm;
public deneme(Context mcontext){
this.mcontext = mcontext;
}
public String macadress(){
wm = (WifiManager)mcontext.getSystemService(Context.WIFI_SERVICE);
String m_szWLANMAC = wm.getConnectionInfo().getMacAddress();
return m_szWLANMAC;
}}
but the method returns null. I have permission ACCESS_WIFI_STATE.
source
share