Commit a2eefc11 authored by Kesha Antonov's avatar Kesha Antonov

use wifi info only for 2 funcs

parent 61cdeaa2
......@@ -40,10 +40,6 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
super(reactContext);
this.reactContext = reactContext;
WifiManager manager = (WifiManager) reactContext.getSystemService(Context.WIFI_SERVICE);
this.wifiInfo = manager.getConnectionInfo();
}
@Override
......@@ -51,6 +47,14 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
return "RNDeviceInfo";
}
private WifiInfo getWifiInfo() {
if ( this.wifiInfo == null ) {
WifiManager manager = (WifiManager) reactContext.getSystemService(Context.WIFI_SERVICE);
this.wifiInfo = manager.getConnectionInfo();
}
return this.wifiInfo;
}
private String getCurrentLanguage() {
Locale current = getReactApplicationContext().getResources().getConfiguration().locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
......@@ -95,13 +99,13 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
@ReactMethod
public void getIpAddress(Promise p) {
String ipAddress = Formatter.formatIpAddress(wifiInfo.getIpAddress());
String ipAddress = Formatter.formatIpAddress(getWifiInfo().getIpAddress());
p.resolve(ipAddress);
}
@ReactMethod
public void getMacAddress(Promise p) {
String macAddress = wifiInfo.getMacAddress();
String macAddress = getWifiInfo().getMacAddress();
p.resolve(macAddress);
}
......
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