From 290c3bffa3d34bcd2af193c6f7468ec652ace6c2 Mon Sep 17 00:00:00 2001 From: wolfy2k Date: Wed, 30 Aug 2017 18:29:01 +0200 Subject: [PATCH 1/3] AppName Inroduced applicationName, tested on ios and android. --- README.md | 3 ++- RNDeviceInfo/RNDeviceInfo.m | 1 + .../com/learnium/RNDeviceInfo/RNDeviceModule.java | 13 +++++++++---- deviceinfo.d.ts | 1 + deviceinfo.js | 3 +++ windows/RNDeviceInfo/RNDeviceInfoModule.cs | 8 +++++--- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 289dc3646..e5a4e8571 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,8 @@ var DeviceInfo = require('react-native-device-info'); | App Instance ID | `getInstanceID()` | | ANDROID ONLY - see https://developers.google.com/instance-id/ | | App is running in emulator | `isEmulator()` | true | if app is running in emulator return true | | App is running on a tablet | `isTablet()` | true | if app is running on a tablet return true | -| PIN or fingerprint set | `isPinOrFingerprintSet()(callback)`| | Only supported in Android and iOS 9.0 and above +| PIN or fingerprint set | `isPinOrFingerprintSet()(callback)`| | Only supported in Android and iOS 9.0 and above | +| App Name | `getApplicationName()` | 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: diff --git a/RNDeviceInfo/RNDeviceInfo.m b/RNDeviceInfo/RNDeviceInfo.m index 346d8757f..2bd2dc0e4 100644 --- a/RNDeviceInfo/RNDeviceInfo.m +++ b/RNDeviceInfo/RNDeviceInfo.m @@ -179,6 +179,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"], diff --git a/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java b/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java index 680a7709f..c173e3ee3 100644 --- a/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java +++ b/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java @@ -4,6 +4,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.os.Build; @@ -85,15 +86,19 @@ public void isPinOrFingerprintSet(Callback callback) { 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 info = packageManager.getPackageInfo(packageName, 0); - constants.put("appVersion", info.versionName); - constants.put("buildNumber", info.versionCode); + PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0); + ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0); + constants.put("appVersion", packageInfo.versionName); + constants.put("buildNumber", packageInfo.versionCode); + constants.put("appName", packageManager.getApplicationLabel(applicationInfo).toString()); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } diff --git a/deviceinfo.d.ts b/deviceinfo.d.ts index e3dcd5c87..a6689c8c5 100644 --- a/deviceinfo.d.ts +++ b/deviceinfo.d.ts @@ -10,6 +10,7 @@ declare class DeviceInfo { public static getSystemName(): string; public static getSystemVersion(): string; public static getBundleId(): string; + public static getApplicationName(): string; public static getBuildNumber(): string; public static getVersion(): string; public static getReadableVersion(): string; diff --git a/deviceinfo.js b/deviceinfo.js index 0a9b7f987..8b290bf4b 100644 --- a/deviceinfo.js +++ b/deviceinfo.js @@ -32,6 +32,9 @@ module.exports = { getBundleId: function() { return RNDeviceInfo.bundleId; }, + getApplicationName: function() { + return RNDeviceInfo.appName; + }, getBuildNumber: function() { return RNDeviceInfo.buildNumber; }, diff --git a/windows/RNDeviceInfo/RNDeviceInfoModule.cs b/windows/RNDeviceInfo/RNDeviceInfoModule.cs index b04e15904..a968405bc 100644 --- a/windows/RNDeviceInfo/RNDeviceInfoModule.cs +++ b/windows/RNDeviceInfo/RNDeviceInfoModule.cs @@ -52,7 +52,8 @@ public override IReadOnlyDictionary Constants 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 { @@ -94,7 +95,7 @@ public override IReadOnlyDictionary Constants catch { } - + constants["instanceId"] = "not available"; constants["deviceName"] = deviceName; constants["systemName"] = "Windows"; @@ -106,7 +107,8 @@ public override IReadOnlyDictionary Constants 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); From af2140734822063ed1920ebd36eb2e581c7264c9 Mon Sep 17 00:00:00 2001 From: Viktor Dlouhy Date: Sat, 13 Jan 2018 01:09:24 +0100 Subject: [PATCH 2/3] Update CHANGELOG.md (#2) --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d520e6b16..68e8dc1ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From e533ed7942f349c4b13cf11731b5231202e529f0 Mon Sep 17 00:00:00 2001 From: Viktor Dlouhy Date: Sat, 13 Jan 2018 01:11:03 +0100 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1fcc8ffff..55d56721d 100644 --- a/README.md +++ b/README.md @@ -195,7 +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()` | Learnium Mobile | | +| 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: