Skip to content

Commit

Permalink
feat: add appId and appName to device info (#3244)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahnuh committed Jul 13, 2020
1 parent 861874f commit 0d5e132
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
Expand Up @@ -3,6 +3,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.ApplicationInfo;
import android.os.BatteryManager;
import android.os.Environment;
import android.os.StatFs;
Expand Down Expand Up @@ -32,6 +33,8 @@ public void getInfo(PluginCall call) {
r.put("osVersion", android.os.Build.VERSION.RELEASE);
r.put("appVersion", getAppVersion());
r.put("appBuild", getAppBuild());
r.put("appId", getAppBundleId());
r.put("appName", getAppName());
r.put("platform", getPlatform());
r.put("manufacturer", android.os.Build.MANUFACTURER);
r.put("uuid", getUuid());
Expand Down Expand Up @@ -91,6 +94,25 @@ private String getAppBuild() {
}
}

private String getAppBundleId() {
try {
PackageInfo pinfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0);
return pinfo.packageName;
} catch(Exception ex) {
return "";
}
}

private String getAppName() {
try {
ApplicationInfo applicationInfo = getContext().getApplicationInfo();
int stringId = applicationInfo.labelRes;
return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : getContext().getString(stringId);
} catch(Exception ex) {
return "";
}
}

private String getPlatform() {
return "android";
}
Expand Down
8 changes: 8 additions & 0 deletions core/src/core-plugin-definitions.ts
Expand Up @@ -487,6 +487,14 @@ export interface DeviceInfo {
* The current bundle build of the app
*/
appBuild: string;
/**
* The bundle id of the app
*/
appId: string;
/**
* The display name of the app
*/
appName: string;
/**
* The operating system of the device
*/
Expand Down
2 changes: 2 additions & 0 deletions core/src/web/device.ts
Expand Up @@ -28,6 +28,8 @@ export class DevicePluginWeb extends WebPlugin implements DevicePlugin {
platform: <'web'> 'web',
appVersion: '',
appBuild: '',
appId: '',
appName: '',
operatingSystem: uaFields.operatingSystem,
osVersion: uaFields.osVersion,
manufacturer: navigator.vendor,
Expand Down
2 changes: 2 additions & 0 deletions electron/src/electron/device.ts
Expand Up @@ -20,6 +20,8 @@ export class DevicePluginElectron extends WebPlugin implements DevicePlugin {
platform: <'electron'> 'electron',
appVersion: app.getVersion(),
appBuild: '',
appId: '',
appName: '',
operatingSystem: info.operatingSystem,
osVersion: info.osVersion,
manufacturer: navigator.vendor,
Expand Down
2 changes: 2 additions & 0 deletions ios/Capacitor/Capacitor/Plugins/Device.swift
Expand Up @@ -26,6 +26,8 @@ public class CAPDevicePlugin: CAPPlugin {
"osVersion": UIDevice.current.systemVersion,
"appVersion": Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "",
"appBuild": Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "",
"appId": Bundle.main.infoDictionary?["CFBundleIdentifier"] as? String ?? "",
"appName": Bundle.main.infoDictionary?["CFBundleDisplayName"] as? String ?? "",
"platform": "ios",
"manufacturer": "Apple",
"uuid": UIDevice.current.identifierForVendor!.uuidString,
Expand Down

0 comments on commit 0d5e132

Please sign in to comment.