Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAC Address always returns 02:00:00:00:00:00; Serial Number not valid as well #293

Closed
natterstefan opened this issue Jan 11, 2018 · 4 comments

Comments

@natterstefan
Copy link

Hi, I am using the latest version of your package and encounter the following issues:

  • MAC Address always returns a wrong address
  • Serial Number is not valid, means I cannot find the result in the "About Device" Settings

Probably this PR is related (not tested/verified though): #150

I've read the following on stackoverflow:

(...) To provide users with greater data protection, starting in this release, Android removes programmatic access to the device’s local hardware identifier for apps using the Wi-Fi and Bluetooth APIs. The WifiInfo.getMacAddress() and the BluetoothAdapter.getAddress() methods now return a constant value of 02:00:00:00:00:00. (...)

Could this help somehow? ==> https://stackoverflow.com/questions/44613285/how-do-i-get-local-mac-address-of-my-mobiles-own-bluetooth-in-react-native

Does anyone encounter these issues as well? Thanks for your help.

@yuansun235
Copy link

package com.learnium.RNDeviceInfo;

import android.Manifest;
import android.app.KeyguardManager;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiInfo;
import android.os.Build;
import android.provider.Settings.Secure;
import android.webkit.WebSettings;
import android.telephony.TelephonyManager;
import android.text.format.Formatter;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.Promise;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.net.NetworkInterface;
import java.util.Collections;
import java.util.List;

import javax.annotation.Nullable;

public class RNDeviceModule extends ReactContextBaseJavaModule {
...
@ReactMethod
public void getMacAddress(Promise p) {
String macAddress = getWifiInfo().getMacAddress();

try {
	List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
	for (NetworkInterface nif : all) {
		if (!nif.getName().equalsIgnoreCase("wlan0")) continue;

		byte[] macBytes = nif.getHardwareAddress();
		if (macBytes == null) {
			macAddress = "";
		}

		StringBuilder res1 = new StringBuilder();
		for (byte b : macBytes) {
			//res1.append(Integer.toHexString(b & 0xFF) + ":");
			res1.append(String.format("%02X:",b));
		}

		if (res1.length() > 0) {
			res1.deleteCharAt(res1.length() - 1);
		}
		macAddress = res1.toString();
	}
} catch (Exception ex) {
	//Log.d("DEBUG", ex.getMessage());
}	
p.resolve(macAddress);

}

...
}

Please rewrite the RNDeviceModule.java's getMacAddress() function like the above.

Thanks!

@machour
Copy link
Contributor

machour commented Jan 30, 2018

Hi @yuansun235. The best thing would probably be to open a PR for this :)

@machour
Copy link
Contributor

machour commented Mar 7, 2018

getMACAddress() was fixed in 0.17.4

As for the serial, we're using Build.SERIAL that seems to work well on my OnePlus 5T (don't mind the mac address in the screenshot):

Test Settings
screenshot_20180307-125418 screenshot_20180307-125412

Could you please re-open a new issue for the serial problem, providing more information?

@machour machour closed this as completed Mar 7, 2018
@natterstefan
Copy link
Author

Hi @machour, I will test it (as soon as I can) and re-open it if needed. Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants