Commit be821028 authored by Gant Laborde's avatar Gant Laborde Committed by GitHub

Merge pull request #150 from passabilities/serial

Add Android support for serial number, IP, and MAC address.
parents 71796205 712e1ee0
......@@ -190,6 +190,9 @@ var DeviceInfo = require('react-native-device-info');
| Phone Number | `getPhoneNumber()` | "2348675309" or "" or null | Only supported in Android |
| First Install Time | `getFirstInstallTime()` | 1505607068808 | Only supported in Android |
| Last Install Time | `getLastUpdateTime()` | 1505607068808 | Only supported in Android |
| Serial Number | `getSerialNumber()` | | Only supported in Android
| IP Address | `getIPAddress()` | | Only supported in Android
| MAC Address | `getMACAddress()` | | Only supported in Android
Since the device setting for PIN/Fingerprint can be modified while the app is still open, this is available via callback instead of as a constant. To use, pass a callback function to the returned bridge function in your javascript:
......
......@@ -7,10 +7,13 @@ 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.google.android.gms.iid.InstanceID;
......@@ -18,6 +21,7 @@ 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;
......@@ -30,9 +34,16 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
ReactApplicationContext reactContext;
WifiInfo wifiInfo;
public RNDeviceModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
WifiManager manager = (WifiManager) reactContext.getSystemService(Context.WIFI_SERVICE);
this.wifiInfo = manager.getConnectionInfo();
}
@Override
......@@ -82,6 +93,18 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
callback.invoke(keyguardManager.isKeyguardSecure());
}
@ReactMethod
public void getIpAddress(Promise p) {
String ipAddress = Formatter.formatIpAddress(wifiInfo.getIpAddress());
p.resolve(ipAddress);
}
@ReactMethod
public void getMacAddress(Promise p) {
String macAddress = wifiInfo.getMacAddress();
p.resolve(macAddress);
}
@Override
public @Nullable Map<String, Object> getConstants() {
HashMap<String, Object> constants = new HashMap<String, Object>();
......@@ -115,6 +138,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
}
constants.put("instanceId", InstanceID.getInstance(this.reactContext).getId());
constants.put("serialNumber", Build.SERIAL);
constants.put("deviceName", deviceName);
constants.put("systemName", "Android");
constants.put("systemVersion", Build.VERSION.RELEASE);
......
......@@ -11,6 +11,15 @@ module.exports = {
getInstanceID: function() {
return RNDeviceInfo.instanceId;
},
getSerialNumber: function () {
return RNDeviceInfo.serialNumber;
},
getIPAddress: function () {
return RNDeviceInfo.getIpAddress();
},
getMACAddress: function () {
return RNDeviceInfo.getMacAddress();
},
getDeviceId: function () {
return RNDeviceInfo.deviceId;
},
......@@ -74,5 +83,7 @@ module.exports = {
getLastUpdateTime: function () {
return RNDeviceInfo.lastUpdateTime;
},
getPhoneNumber: _ => RNDeviceInfo.phoneNumber
getPhoneNumber: function () {
return RNDeviceInfo.phoneNumber;
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment