我有两个类:其中一个是活动类,另一个是非活动类.我调用一个非活动类中的方法来返回mac Adress.
活动类:
public class Control extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
deneme d = new deneme(this); // i has tried (getApplicatonContext)
String x = d.macadress();
Toast.makeText(getApplicationContext(),x,Toast.LENGTH_LONG).show();
}}
和非活动类:
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;
}}
但该方法返回null.我有权限ACCESS_WIFI_STATE.