Skip to content

Commit

Permalink
feat(device): Add deviceInfo.name implementation for Android (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaanWasscher committed Nov 2, 2020
1 parent ac94af0 commit bdc3b38
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion device/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Get the device's current language locale code.

| Prop | Type | Description | Since |
| --------------------- | ------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| **`name`** | <code>string</code> | The name of the device. For example, "John's iPhone". This is only supported on iOS. | 1.0.0 |
| **`name`** | <code>string</code> | 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`** | <code>string</code> | The device model. For example, "iPhone". | 1.0.0 |
| **`platform`** | <code>"ios" \| "android" \| "web"</code> | The device platform (lowercase). | 1.0.0 |
| **`uuid`** | <code>string</code> | 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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion device/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit bdc3b38

Please sign in to comment.