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

Android UniqueID functionality #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableNativeArray;

import static android.provider.Settings.Secure.getString;

import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -159,6 +161,14 @@ private String getAppVersion() {
}
}

private String getUniqueID() {
try {
return Settings.Secure.getString(getReactApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
} catch (Exception e) {
return "unknown";
}
}

private String getBuildNumber() {
try {
return Integer.toString(getPackageInfo().versionCode);
Expand Down Expand Up @@ -238,6 +248,7 @@ public Map<String, Object> getConstants() {
constants.put("appBuildNumber", this.getBuildNumber());
constants.put("appBundleId", this.getBundleId());
constants.put("deviceId", this.getDeviceId());
constants.put("uniqueId", this.getUniqueID());
constants.put("deviceName", this.getDeviceName());
constants.put("deviceType", this.getDeviceType().getValue());
constants.put("deviceModel", this.getModel());
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export default {
// marketing device ID, e.g. "iPhone 11"
deviceName: DeviceConstants.deviceName,

// unique ID, e.g. ""9547b2fs7d8bhd8e""
uniqueId: DeviceConstants.uniqueId,

// One of: "Handset", "Tablet", "Tv", "Unknown"
deviceType: DeviceConstants.deviceType,

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-device-constants",
"title": "React Native Device Constants",
"version": "1.0.0",
"version": "1.0.2",
"description": "TODO",
"main": "index.js",
"scripts": {
Expand Down