diff --git a/device/README.md b/device/README.md index 04236d0f9..5e2895fff 100644 --- a/device/README.md +++ b/device/README.md @@ -75,7 +75,7 @@ Get the device's current language locale code. | Prop | Type | Description | Since | | --------------------- | ------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- | ----- | -| **`name`** | string | The name of the device. For example, "John's iPhone". This is only supported on iOS. | 1.0.0 | +| **`name`** | string | The name of the device. For example, "John's iPhone". This is only supported on iOS and Android 7.1 or above. | 1.0.0 | | **`model`** | string | The device model. For example, "iPhone". | 1.0.0 | | **`platform`** | "ios" \| "android" \| "web" | The device platform (lowercase). | 1.0.0 | | **`uuid`** | string | The UUID of the device as available to the app. This identifier may change on modern mobile platforms that only allow per-app install UUIDs. | 1.0.0 | diff --git a/device/android/src/main/java/com/capacitorjs/plugins/device/Device.java b/device/android/src/main/java/com/capacitorjs/plugins/device/Device.java index 6a8649784..11dbbb7c6 100644 --- a/device/android/src/main/java/com/capacitorjs/plugins/device/Device.java +++ b/device/android/src/main/java/com/capacitorjs/plugins/device/Device.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; +import android.os.Build; import android.os.Environment; import android.os.StatFs; import android.provider.Settings; @@ -69,4 +70,12 @@ public boolean isCharging() { public boolean isVirtual() { return android.os.Build.FINGERPRINT.contains("generic") || android.os.Build.PRODUCT.contains("sdk"); } + + public String getName() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { + return Settings.Global.getString(this.context.getContentResolver(), Settings.Global.DEVICE_NAME); + } + + return null; + } } diff --git a/device/android/src/main/java/com/capacitorjs/plugins/device/DevicePlugin.java b/device/android/src/main/java/com/capacitorjs/plugins/device/DevicePlugin.java index c3133adb0..2c061b299 100644 --- a/device/android/src/main/java/com/capacitorjs/plugins/device/DevicePlugin.java +++ b/device/android/src/main/java/com/capacitorjs/plugins/device/DevicePlugin.java @@ -31,6 +31,7 @@ public void getInfo(PluginCall call) { r.put("manufacturer", android.os.Build.MANUFACTURER); r.put("uuid", implementation.getUuid()); r.put("isVirtual", implementation.isVirtual()); + r.put("name", implementation.getName()); call.resolve(r); } diff --git a/device/src/definitions.ts b/device/src/definitions.ts index 3b411a452..25b00dbe2 100644 --- a/device/src/definitions.ts +++ b/device/src/definitions.ts @@ -10,7 +10,7 @@ export interface DeviceInfo { /** * The name of the device. For example, "John's iPhone". * - * This is only supported on iOS. + * This is only supported on iOS and Android 7.1 or above. * * @since 1.0.0 */