NJS how to get Android phone MAC address above Android version 8.0

problem description

now I use the official website of H5+MUI+vue developers to get MAC addresses that are not easy to use, either to report an error or to report an error or to report an error. This is not an actual address at all, so I want to ask the great god how to get it. I don"t know much about NJS. I can"t query

.

the environmental background of the problems and what methods you have tried

tried it all

related codes

/ / Please paste the code text below (do not replace the code with pictures)

 function getMac() {
        var Context = plus.android.importClass("android.content.Context");
        var wifiManager = plus.android.runtimeMainActivity().getSystemService(Context.WIFI_SERVICE);
        var wifiInfo = plus.android.invoke(wifiManager, "getConnectionInfo");
        var mac = plus.android.invoke(wifiInfo, "getMacAddress");
        alert(mac);//02:00:00:00:00

    }

what result do you expect? What is the error message actually seen?

Jan.28,2022

function getMac() {
    var mac = "xxx-xxx-xxx-xxx";
    if (plus.os.name == "Android") {
    //WifiManager
        var Context = plus.android.importClass("android.content.Context");
        var WifiManager = plus.android.importClass("android.net.wifi.WifiManager");
        var wifiManager = plus.android.runtimeMainActivity().getSystemService(Context.WIFI_SERVICE);
        var WifiInfo = plus.android.importClass("android.net.wifi.WifiInfo");
        var wifiInfo = wifiManager.getConnectionInfo();
        mac = wifiInfo.getMacAddress();
    }
    return mac;
}

The

code is fine. It should be the system that restricts

.
access to hardware identifiers
to provide stricter data protection for users, starting from this version, Android removes programmatic access to device local hardware identifiers for applications that use WLAN API and Bluetooth API. The WifiInfo.getMacAddress () method and the BluetoothAdapter.getAddress () method now return a constant value of 02-00-00-00-00-00-00.

Android 6.0change

After

7.0, it seems to have let go again and saw a solution (not tested).

DeviceAdminReceiver admin = new DeviceAdminReceiver();
DevicePolicyManager devicepolicymanager = admin.getManager(getApplicationContext());
ComponentName name1 = admin.getWho(getApplicationContext());
if (devicepolicymanager.isAdminActive(name1)){
            String mac_address = devicepolicymanager.getWifiMacAddress(name1);
            Log.e("macAddress",""+mac_address);
}

that is to say, if it's not Android 8, Android 6. 0 has changed. The old code cannot be used, but the new code can be tried after 7.0.

Menu