User

The User object represents the user who is being tracked. The identifier of the user is used in the SDK to identify the tracking device.

The User object

Method Type Description
getId uuid String Unique identifier for the object
getName String Name of the user
getPhone String Phone number of user
getGroupId String The id of the fleet to which this user belongs
getGroup Group Contains id, name, uniqueId of a group object
getUniqueId String A unique id that was added to the user to identify
getLocation HyperTrackLocation Location of user as HyperTrackLocation object
getActivity Activity Activity of user as Activity object
getHealth Health Health of user as Health object. See below for more detail.
getLastHeartbeatAt Date Date time for last communication with the user's device
getCreatedAt Date Timestamp of when user was created
isConnected boolean Is user device connected with HyperTrackServer

Health

  • batteryPercentage : Current battery percentage of user's device
  • locationStatus : Possible values location_not_available, location_available
  • networkStatus: Possible values network_offline

GetOrCreate User

Call this method to get or create a User on HyperTrack API Server for the current device.

[info] User already created?

You can set an existing user id, in case you have created an user id via the backend API using the userParams.setId("YOUR_USER_ID") method in the SDK. When setting userId don't set any other params as all other params except id will get ignored. And if user is not exist with given id then API will returns a error.

Note : If uniqueId is passed along with other params then if user is already exist on HyperTrack server with given uniqueId then you will get the already created User object and all other params will get ignored otherwise create a new user with all params.

UniqueId can be used to get or create user while id can be used to only get user.

UserParams

Parameter Name Type Method Name Description
name String setName Name of the user
phone String setPhone Phone number of the user
photo String setPhoto Web URL of photo file or Base64 string of user image file
uniqueId String setUniqueIdId A unique string identifier used to identify user on HyperTrack API server
groupId uuid String setGroupId A uuid string for group created on HyperTrack API server
UserParams userParams = new UserParams().setName(name)
                .setPhone(phoneNumber)
                .setPhoto(encodedImage)
                .setUniqueId(phoneNumber)
                .setGroupId(groupId);

// getOrCreateUser API with Unique_id param will create a new user only if none exists already for the given Unique_id.
HyperTrack.getOrCreateUser(userParams, new HyperTrackCallback() {
   @Override
   public void onSuccess(@NonNull SuccessResponse response) {
       if (response.getResponseObject() != null) {
            User user = (User) response.getResponseObject();
            String userId = user.getId();
            // Handle user_id, if needed
            ...
       }
   }

   @Override
   public void onError(@NonNull ErrorResponse error) {
       // Handle createUser error here
       Toast.makeText(this, error.getErrorMessage(), Toast.LENGTH_SHORT).show();
   }
});

Update User

Call HyperTrack.updateUser() API to update the user details.

UserParams userParams = new UserParams().setName(name)
                .setPhone(phoneNumber)
                .setPhoto(encodedImage)
                .setUniqueId(phoneNumber)
                .setGroupId(groupId);

HyperTrack.updateUser(userParams, new HyperTrackCallback() {
    @Override
    public void onSuccess(@NonNull SuccessResponse successResponse) {
        if (response.getResponseObject() != null) {
            User user = (User) response.getResponseObject();
            // Handle user_id, if needed
            String userId = user.getId();

            ...
        }
    }
    @Override
    public void onError (@NonNull ErrorResponse errorResponse){
        // Handle updateUser error here
        Toast.makeText(this, error.getErrorMessage(), Toast.LENGTH_SHORT).show();
    }
    });
}

Get UserId

Call HyperTrack.getUserId() API to get UserId configured in the SDK casted as a String.

String userId = HyperTrack.getUserId();

results matching ""

    No results matching ""