Commit 6d0a9cfe authored by IjzerenHein's avatar IjzerenHein

Added `getTotalMemory()` and `getMaxMemory()` functions

parent c1e93065
......@@ -190,10 +190,13 @@ var DeviceInfo = require('react-native-device-info');
| Phone Number | `getPhoneNumber()` | `?string` e.g. "2348675309" or "" | Only supported in Android |
| First Install Time | `getFirstInstallTime()` | `number` e.g. 1505607068808 | Only supported in Android |
| Last Install Time | `getLastUpdateTime()` | `number` e.g. 1505607068808 | Only supported in Android |
| Serial Number | `getSerialNumber()` | `string` | Only supported in Android
| IP Address | `getIPAddress()` | `Promise<string>` | Only supported in Android
| MAC Address | `getMACAddress()` | `Promise<string>` | Only supported in Android
| Carrier | `getCarrier()` | `string` e.g. "SOFTBANK" | | |
| Serial Number | `getSerialNumber()` | `string` | Only supported in Android |
| IP Address | `getIPAddress()` | `Promise<string>` | Only supported in Android |
| MAC Address | `getMACAddress()` | `Promise<string>` | Only supported in Android |
| Carrier | `getCarrier()` | `string` e.g. "SOFTBANK" | |
| Total Memory | `getTotalMemory()` | `number` e.g. 1995018240 | Total ammount of memory on the device |
| Max Memory | `getMaxMemory()` | `number` e.g. 268435456 | ANDROID ONLY - see https://developer.android.com/reference/java/lang/Runtime.html#maxMemory() |
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:
```js
......
......@@ -200,6 +200,10 @@ RCT_EXPORT_MODULE(RNDeviceInfo)
return ([format rangeOfString:@"a"].location == NSNotFound);
}
- (unsigned long long) totalMemory {
return [NSProcessInfo processInfo].physicalMemory;
}
- (NSDictionary *)constantsToExport
{
UIDevice *currentDevice = [UIDevice currentDevice];
......@@ -227,6 +231,7 @@ RCT_EXPORT_MODULE(RNDeviceInfo)
@"isEmulator": @(self.isEmulator),
@"isTablet": @(self.isTablet),
@"is24Hour": @(self.is24Hour),
@"totalMemory": @(self.totalMemory)
};
}
......
......@@ -14,6 +14,7 @@ import android.provider.Settings.Secure;
import android.webkit.WebSettings;
import android.telephony.TelephonyManager;
import android.text.format.Formatter;
import android.app.ActivityManager;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
......@@ -25,6 +26,7 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.lang.Runtime;
import javax.annotation.Nullable;
......@@ -188,6 +190,14 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants.put("phoneNumber", telMgr.getLine1Number());
}
constants.put("carrier", this.getCarrier());
Runtime rt = Runtime.getRuntime();
constants.put("maxMemory", rt.maxMemory());
ActivityManager actMgr = (ActivityManager) this.reactContext.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
actMgr.getMemoryInfo(memInfo);
constants.put("totalMemory", memInfo.totalMem);
return constants;
}
}
......@@ -30,3 +30,5 @@ export function getMACAddress(): Promise<string>;
export function getPhoneNumber(): string;
export function getAPILevel(): number;
export function getCarrier(): string;
export function getTotalMemory(): number;
export function getMaxMemory(): number;
......@@ -92,4 +92,10 @@ module.exports = {
getCarrier: function() {
return RNDeviceInfo.carrier;
},
getTotalMemory: function() {
return RNDeviceInfo.totalMemory;
},
getMaxMemory: function() {
return RNDeviceInfo.maxMemory;
},
};
......@@ -30,4 +30,6 @@ declare module.exports: {
getIPAddress: () => Promise<string>,
getMACAddress: () => Promise<string>,
getCarrier: () => string,
getTotalMemory: () => number,
getMaxMemory: () => number,
}
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