diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Device.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Device.java index 9858f974b3..093e5c8bb4 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Device.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/Device.java @@ -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; @@ -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()); @@ -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"; } diff --git a/core/src/core-plugin-definitions.ts b/core/src/core-plugin-definitions.ts index c9b6a6efa7..de8f92ced1 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -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 */ diff --git a/core/src/web/device.ts b/core/src/web/device.ts index 4889b5808d..ca3eead93f 100644 --- a/core/src/web/device.ts +++ b/core/src/web/device.ts @@ -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, diff --git a/electron/src/electron/device.ts b/electron/src/electron/device.ts index 6bd5ee2dcc..dd9583ba80 100644 --- a/electron/src/electron/device.ts +++ b/electron/src/electron/device.ts @@ -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, diff --git a/ios/Capacitor/Capacitor/Plugins/Device.swift b/ios/Capacitor/Capacitor/Plugins/Device.swift index c120a74e99..76aac469cd 100644 --- a/ios/Capacitor/Capacitor/Plugins/Device.swift +++ b/ios/Capacitor/Capacitor/Plugins/Device.swift @@ -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,