在Android 6.0上获取wifi mac

时间:2017-01-18 08:44:10

标签: java android

我有一个使用MAC地址注册的应用程序。众所周知,从Android 6.0开始,你就不能再使用旧方法来做到这一点。我的问题是它似乎不是一个直接获取的MAC地址。希望有人可以帮助建议一种方法来使这个工作在Android 6.0 +

我的代码如下;

public void getMacAddress()
{
    WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    WifiInfo wInfo = wifiManager.getConnectionInfo();
    String macAddress = wInfo.getMacAddress();
    Log.e("address", "mac address:" + macAddress);
    pref = getSharedPreferences(Constant.PREF_APPDATA, MODE_PRIVATE);
    edit=pref.edit();

    if(macAddress!=null)
        edit.putString(Constant.P_DEVICEID, macAddress);
//  else
//      Toast.makeText(this," WiFi MAC address not found.", Toast.LENGTH_SHORT).show();

    TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
    if( tm.getDeviceId()== null)
    {
        //edit.putBoolean(Constant.P_IS_TABLET, true);
        //Toast.makeText(Activity_Audio.this, "Tablet", Toast.LENGTH_SHORT).show();
    }
    else
    {
        //Toast.makeText(Activity_Audio.this, "Not Tablet", Toast.LENGTH_SHORT).show();
    }

    edit.commit();
}

0 个答案:

没有答案