Skip to content

Commit

Permalink
Merge pull request #210 from wolfy2k/master
Browse files Browse the repository at this point in the history
Introduced applicationName
  • Loading branch information
GantMan committed Jan 15, 2018
2 parents 2534b74 + e533ed7 commit 583f7f5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
- Make play-services optional (https://github.com/rebeccahughes/react-native-device-info/pull/226)
- Critical fix on WIFI STATE (https://github.com/rebeccahughes/react-native-device-info/pull/249)
- Added `getTotalMemory` and `getMaxMemory` (https://github.com/rebeccahughes/react-native-device-info/pull/289)
- Introduced `getApplicationName` to see the name of the app both on ios, android and win (https://github.com/rebeccahughes/react-native-device-info/pull/210)

### 0.12.0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -163,7 +163,6 @@ See [CHANGELOG.md](https://github.com/rebeccahughes/react-native-device-info/blo
var DeviceInfo = require('react-native-device-info');
// or import DeviceInfo from 'react-native-device-info';
```

| Name | Method | Return | Notes |
| :------------------------- | :------------------------------- | :-------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------- |
| Device Unique ID | `getUniqueID()` | `string` e.g. "FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9" | This is IDFV on iOS so it will change if all apps from the current apps vendor have been previously uninstalled. |
Expand Down Expand Up @@ -196,6 +195,7 @@ var DeviceInfo = require('react-native-device-info');
| Carrier | `getCarrier()` | `string` e.g. "SOFTBANK" | |
| Total Memory | `getTotalMemory()` | `number` e.g. 1995018240 | Total amount 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() |
| App Name | `getApplicationName()` | `string` e.g.Learnium Mobile | |

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:

Expand Down
1 change: 1 addition & 0 deletions RNDeviceInfo/RNDeviceInfo.m
Expand Up @@ -221,6 +221,7 @@ - (NSDictionary *)constantsToExport
@"deviceLocale": self.deviceLocale,
@"deviceCountry": self.deviceCountry ?: [NSNull null],
@"uniqueId": uniqueId,
@"appName": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"],
@"bundleId": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"],
@"appVersion": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ?: [NSNull null],
@"buildNumber": [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"],
Expand Down
Expand Up @@ -5,6 +5,7 @@
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.net.wifi.WifiManager;
Expand Down Expand Up @@ -125,17 +126,21 @@ public String getCarrier() {

PackageManager packageManager = this.reactContext.getPackageManager();
String packageName = this.reactContext.getPackageName();

String applicationName = this.reactContext.getApplicationInfo().loadLabel(this.reactContext.getPackageManager()).toString();

constants.put("appVersion", "not available");
constants.put("appName", "not available");
constants.put("buildVersion", "not available");
constants.put("buildNumber", 0);

try {
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
PackageInfo info = packageManager.getPackageInfo(packageName, 0);
constants.put("appVersion", info.versionName);
constants.put("buildNumber", info.versionCode);
constants.put("firstInstallTime", info.firstInstallTime);
constants.put("lastUpdateTime", info.lastUpdateTime);
constants.put("appName", packageManager.getApplicationLabel(applicationInfo).toString());
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
Expand Down
1 change: 1 addition & 0 deletions deviceinfo.d.ts
Expand Up @@ -9,6 +9,7 @@ export function getDeviceId(): string;
export function getSystemName(): string;
export function getSystemVersion(): string;
export function getBundleId(): string;
export function getApplicationName(): string;
export function getBuildNumber(): string;
export function getVersion(): string;
export function getReadableVersion(): string;
Expand Down
3 changes: 3 additions & 0 deletions deviceinfo.js
Expand Up @@ -44,6 +44,9 @@ module.exports = {
getBundleId: function() {
return RNDeviceInfo.bundleId;
},
getApplicationName: function() {
return RNDeviceInfo.appName;
},
getBuildNumber: function() {
return RNDeviceInfo.buildNumber;
},
Expand Down
8 changes: 5 additions & 3 deletions windows/RNDeviceInfo/RNDeviceInfoModule.cs
Expand Up @@ -56,7 +56,8 @@ private bool is24Hour()
Package package = Package.Current;
PackageId packageId = package.Id;
PackageVersion version = packageId.Version;
String packageName = package.DisplayName;
String bundleId = packageId.Name;
String appName = package.DisplayName;

try
{
Expand Down Expand Up @@ -98,7 +99,7 @@ private bool is24Hour()
catch
{
}

constants["instanceId"] = "not available";
constants["deviceName"] = deviceName;
constants["systemName"] = "Windows";
Expand All @@ -111,7 +112,8 @@ private bool is24Hour()
constants["deviceCountry"] = culture.EnglishName;
constants["uniqueId"] = device_id;
constants["systemManufacturer"] = manufacturer;
constants["bundleId"] = packageName;
constants["bundleId"] = bundleId;
constants["appName"] = appName;
constants["userAgent"] = "not available";
constants["timezone"] = TimeZoneInfo.Local.Id;
constants["isEmulator"] = IsEmulator(model);
Expand Down

0 comments on commit 583f7f5

Please sign in to comment.