Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deviceInfo.name implementation for Android #88

Merged
merged 6 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. | 1.0.0 |
DaanWasscher marked this conversation as resolved.
Show resolved Hide resolved
| **`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.
DaanWasscher marked this conversation as resolved.
Show resolved Hide resolved
*
* @since 1.0.0
*/
Expand Down