Skip to content

Commit 0d5e132

Browse files
authored
feat: add appId and appName to device info (#3244)
1 parent 861874f commit 0d5e132

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

android/capacitor/src/main/java/com/getcapacitor/plugin/Device.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Intent;
44
import android.content.IntentFilter;
55
import android.content.pm.PackageInfo;
6+
import android.content.pm.ApplicationInfo;
67
import android.os.BatteryManager;
78
import android.os.Environment;
89
import android.os.StatFs;
@@ -32,6 +33,8 @@ public void getInfo(PluginCall call) {
3233
r.put("osVersion", android.os.Build.VERSION.RELEASE);
3334
r.put("appVersion", getAppVersion());
3435
r.put("appBuild", getAppBuild());
36+
r.put("appId", getAppBundleId());
37+
r.put("appName", getAppName());
3538
r.put("platform", getPlatform());
3639
r.put("manufacturer", android.os.Build.MANUFACTURER);
3740
r.put("uuid", getUuid());
@@ -91,6 +94,25 @@ private String getAppBuild() {
9194
}
9295
}
9396

97+
private String getAppBundleId() {
98+
try {
99+
PackageInfo pinfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), 0);
100+
return pinfo.packageName;
101+
} catch(Exception ex) {
102+
return "";
103+
}
104+
}
105+
106+
private String getAppName() {
107+
try {
108+
ApplicationInfo applicationInfo = getContext().getApplicationInfo();
109+
int stringId = applicationInfo.labelRes;
110+
return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : getContext().getString(stringId);
111+
} catch(Exception ex) {
112+
return "";
113+
}
114+
}
115+
94116
private String getPlatform() {
95117
return "android";
96118
}

core/src/core-plugin-definitions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,14 @@ export interface DeviceInfo {
487487
* The current bundle build of the app
488488
*/
489489
appBuild: string;
490+
/**
491+
* The bundle id of the app
492+
*/
493+
appId: string;
494+
/**
495+
* The display name of the app
496+
*/
497+
appName: string;
490498
/**
491499
* The operating system of the device
492500
*/

core/src/web/device.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export class DevicePluginWeb extends WebPlugin implements DevicePlugin {
2828
platform: <'web'> 'web',
2929
appVersion: '',
3030
appBuild: '',
31+
appId: '',
32+
appName: '',
3133
operatingSystem: uaFields.operatingSystem,
3234
osVersion: uaFields.osVersion,
3335
manufacturer: navigator.vendor,

electron/src/electron/device.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export class DevicePluginElectron extends WebPlugin implements DevicePlugin {
2020
platform: <'electron'> 'electron',
2121
appVersion: app.getVersion(),
2222
appBuild: '',
23+
appId: '',
24+
appName: '',
2325
operatingSystem: info.operatingSystem,
2426
osVersion: info.osVersion,
2527
manufacturer: navigator.vendor,

ios/Capacitor/Capacitor/Plugins/Device.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class CAPDevicePlugin: CAPPlugin {
2626
"osVersion": UIDevice.current.systemVersion,
2727
"appVersion": Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "",
2828
"appBuild": Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "",
29+
"appId": Bundle.main.infoDictionary?["CFBundleIdentifier"] as? String ?? "",
30+
"appName": Bundle.main.infoDictionary?["CFBundleDisplayName"] as? String ?? "",
2931
"platform": "ios",
3032
"manufacturer": "Apple",
3133
"uuid": UIDevice.current.identifierForVendor!.uuidString,

0 commit comments

Comments
 (0)