@capawesome/capacitor-device-info 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -2
- package/android/build.gradle +1 -1
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -21,9 +21,15 @@ Capacitor plugin to read device information, such as the model, manufacturer, op
|
|
|
21
21
|
|
|
22
22
|
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
23
23
|
|
|
24
|
-
##
|
|
24
|
+
## Use Cases
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
The Device Info plugin is typically used whenever an app needs to know more about the device it is running on, for example:
|
|
27
|
+
|
|
28
|
+
- **Bug reports and support**: Attach the device model, manufacturer, operating system version, and WebView version to support tickets or crash reports.
|
|
29
|
+
- **Device registration**: Use the per-install identifier to register a device on your backend without collecting personal data.
|
|
30
|
+
- **Adaptive user interfaces**: Adjust your layout based on the device type, for example phone versus tablet.
|
|
31
|
+
- **Feature gating**: Enable or disable features depending on the Android SDK version or the major iOS version.
|
|
32
|
+
- **Diagnostics**: Monitor the memory used by your app or detect whether it is running on an emulator or simulator.
|
|
27
33
|
|
|
28
34
|
## Compatibility
|
|
29
35
|
|
|
@@ -61,6 +67,12 @@ No configuration required for this plugin.
|
|
|
61
67
|
|
|
62
68
|
## Usage
|
|
63
69
|
|
|
70
|
+
The following examples show how to read the device identifier, read device information, and read the device uptime.
|
|
71
|
+
|
|
72
|
+
### Read the device identifier
|
|
73
|
+
|
|
74
|
+
Get a unique per-install identifier for the device, for example to register the device on your backend. See the [API documentation](#getid) for when the identifier is reset on each platform:
|
|
75
|
+
|
|
64
76
|
```typescript
|
|
65
77
|
import { DeviceInfo } from '@capawesome/capacitor-device-info';
|
|
66
78
|
|
|
@@ -68,11 +80,27 @@ const getId = async () => {
|
|
|
68
80
|
const { identifier } = await DeviceInfo.getId();
|
|
69
81
|
return identifier;
|
|
70
82
|
};
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Read device information
|
|
86
|
+
|
|
87
|
+
Get information about the device, such as the model, manufacturer, operating system, device type, and memory. Fields that a platform cannot determine are `null` (see [Platform Support](#platform-support)):
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import { DeviceInfo } from '@capawesome/capacitor-device-info';
|
|
71
91
|
|
|
72
92
|
const getInfo = async () => {
|
|
73
93
|
const info = await DeviceInfo.getInfo();
|
|
74
94
|
return info;
|
|
75
95
|
};
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Read the device uptime
|
|
99
|
+
|
|
100
|
+
Get the time the device has been running since its last boot, in milliseconds. Only available on Android and iOS:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import { DeviceInfo } from '@capawesome/capacitor-device-info';
|
|
76
104
|
|
|
77
105
|
const getUptime = async () => {
|
|
78
106
|
const { uptime } = await DeviceInfo.getUptime();
|
|
@@ -255,6 +283,46 @@ This plugin can be used as a replacement for the official [`@capacitor/device`](
|
|
|
255
283
|
| `getLanguageCode()` | Use the [Localization](https://capawesome.io/docs/sdks/capacitor/localization/) plugin |
|
|
256
284
|
| `getLanguageTag()` | Use the [Localization](https://capawesome.io/docs/sdks/capacitor/localization/) plugin |
|
|
257
285
|
|
|
286
|
+
## FAQ
|
|
287
|
+
|
|
288
|
+
### How is this plugin different from other similar plugins?
|
|
289
|
+
|
|
290
|
+
It gathers a wide range of device details through one fully typed API — model, manufacturer, operating system, a per-install identifier, total and used memory, device type, virtual-device detection, WebView version, and uptime — with consistent behavior across Android, iOS, and the Web. Fields a platform cannot determine are returned as `null`, and the package is actively maintained against the latest Capacitor and OS versions. If you only need the platform name, a minimal setup is enough; if you want a complete, honest picture of the device, this plugin is built for exactly that.
|
|
291
|
+
|
|
292
|
+
### How stable is the identifier returned by `getId`?
|
|
293
|
+
|
|
294
|
+
The identifier is unique per install. On Android, it is the `ANDROID_ID` value, which is reset when the app is reinstalled after the signing key changes or the device is factory reset. On iOS, it is the `identifierForVendor` value, which is reset when all apps from the vendor are uninstalled. On the Web, it is a random UUID persisted in the browser's `localStorage`, which is reset when the browser storage is cleared.
|
|
295
|
+
|
|
296
|
+
### Can this plugin replace the official `@capacitor/device` plugin?
|
|
297
|
+
|
|
298
|
+
Yes, this plugin can be used as a replacement for the official `@capacitor/device` plugin. The `getId()` and `getInfo()` methods map directly, while battery information and language settings are covered by the [Battery](https://capawesome.io/docs/sdks/capacitor/battery/) and [Localization](https://capawesome.io/docs/sdks/capacitor/localization/) plugins. See the [migration table](#migration-from-capacitordevice) above.
|
|
299
|
+
|
|
300
|
+
### Why is the device name always a generic value like `iPhone` on iOS?
|
|
301
|
+
|
|
302
|
+
On iOS 16 and newer, a generic device name is returned unless the app has the required entitlement from Apple. If the name cannot be determined at all, the `name` property is `null`.
|
|
303
|
+
|
|
304
|
+
### Why are some fields `null` on my platform?
|
|
305
|
+
|
|
306
|
+
The plugin returns `null` for any field that a platform cannot determine. For example, `totalMemory` and `usedMemory` are only available on Android and iOS, and `androidSdkVersion` is only available on Android. See the [Platform Support](#platform-support) section for a complete overview.
|
|
307
|
+
|
|
308
|
+
### Can I get the battery level or the device language with this plugin?
|
|
309
|
+
|
|
310
|
+
No, this plugin focuses on device information such as the model, manufacturer, operating system, and memory. For battery information, use the [Battery](https://capawesome.io/docs/sdks/capacitor/battery/) plugin. For the user's language and locale preferences, use the [Localization](https://capawesome.io/docs/sdks/capacitor/localization/) plugin.
|
|
311
|
+
|
|
312
|
+
### Can I use this plugin with Ionic, React, Vue or Angular?
|
|
313
|
+
|
|
314
|
+
Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.
|
|
315
|
+
|
|
316
|
+
## Related Plugins
|
|
317
|
+
|
|
318
|
+
- [Battery](https://capawesome.io/docs/sdks/capacitor/battery/): Access battery information.
|
|
319
|
+
- [Localization](https://capawesome.io/docs/sdks/capacitor/localization/): Read the user's localization preferences, such as preferred locales and time zone.
|
|
320
|
+
- [Network](https://capawesome.io/docs/sdks/capacitor/network/): Access network information.
|
|
321
|
+
|
|
322
|
+
## Newsletter
|
|
323
|
+
|
|
324
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
325
|
+
|
|
258
326
|
## Changelog
|
|
259
327
|
|
|
260
328
|
See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/device-info/CHANGELOG.md).
|
package/android/build.gradle
CHANGED
|
@@ -30,7 +30,7 @@ android {
|
|
|
30
30
|
buildTypes {
|
|
31
31
|
release {
|
|
32
32
|
minifyEnabled false
|
|
33
|
-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
lintOptions {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capawesome/capacitor-device-info",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Capacitor plugin to read device information.",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Capacitor plugin to read device information on Android, iOS, and Web.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/esm/index.d.ts",
|
|
@@ -37,7 +37,15 @@
|
|
|
37
37
|
"keywords": [
|
|
38
38
|
"capacitor",
|
|
39
39
|
"plugin",
|
|
40
|
-
"native"
|
|
40
|
+
"native",
|
|
41
|
+
"capacitor-plugin",
|
|
42
|
+
"device info",
|
|
43
|
+
"device information",
|
|
44
|
+
"device model",
|
|
45
|
+
"device identifier",
|
|
46
|
+
"operating system version",
|
|
47
|
+
"device type",
|
|
48
|
+
"memory usage"
|
|
41
49
|
],
|
|
42
50
|
"scripts": {
|
|
43
51
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|