A sample application demonstrating the use of HyperTrack SDK. This sample app will mock track the device location.
Android Studio with emulator (or test device)
Clone this repository
# Clone this repository
$ git clone https://github.com/hypertrack/quickstart-android.git
- Signup here.
- Get
test
publishable key from dashboard settings page. - Add the test publishable key to MyApplication file.
HyperTrack.initialize(this.getApplicationContext(), TEST_PUBLISHABLE_KEY);
The SDK has a bi-directional communication model with the server. This enables the SDK to run on a variable frequency model, which balances the fine trade-off between low latency tracking and battery efficiency, and improve robustness. For this purpose, the Android SDK uses FCM or GCM silent notifications.
By default, project is configured with test google-service.json
credentials.
You need to add FCM Server Key AAAAckZ1H20:APA91bEyilv0qgVyfSECb-jZxsgetGyKyJGVIavCOLhWn5GdI0aQBz76dPKAf5P73fVBE7OXoS5QicAV5ASrmcyhizGnNbD0DhwJPVSZaLKQrRGYH3Bam-7WGe3OEX_Chhf7CEPToVw0
on HyperTrack dashboard settings page.
**Note:**But if you want to use your FCM configuration then replace FCM Server Key
on HyperTrack dashboard settings page with yours FCM server key and replace
google-service.json .
Ask for location permission
and location services
. Refer here for more detail
// Check for Location permission
if (!HyperTrack.checkLocationPermission(this)) {
HyperTrack.requestPermissions(this);
return;
}
// Check for Location settings
if (!HyperTrack.checkLocationServices(this)) {
HyperTrack.requestLocationServices(this);
}
The next thing that you need to do is to create a HyperTrack user. More details about the function here.
When the user is created, we need to start mock tracking
his location and activity. Call the following method to do so HyperTrack.startMockTracking()
. Refer here for more detail.
// Get User details, if specified
final String name = nameText.getText().toString();
final String phoneNumber = phoneNumberText.getText().toString();
final String lookupId = !HTTextUtils.isEmpty(lookupIdText.getText().toString()) ?
lookupIdText.getText().toString() : phoneNumber;
UserParams userParams = new UserParams().setName(name).setPhone(phoneNumber).setLookupId(lookupId);
/**
* Get or Create a User for given lookupId on HyperTrack Server here to
* login your user & configure HyperTrack SDK with this generated
* HyperTrack UserId.
* OR
* Implement your API call for User Login and get back a HyperTrack
* UserId from your API Server to be configured in the HyperTrack SDK.
*/
HyperTrack.getOrCreateUser(userParams, new HyperTrackCallback() {
@Override
public void onSuccess(@NonNull SuccessResponse successResponse) {
User user = (User) successResponse.getResponseObject();
String userId = user.getId();
// Handle createUser success here, if required
// HyperTrack SDK auto-configures UserId on createUser API call,
// so no need to call HyperTrack.setUserId() API
// On UserLogin success
HyperTrack.startMockTracking();
}
@Override
public void onError(@NonNull ErrorResponse errorResponse) {
Toast.makeText(LoginActivity.this, R.string.login_error_msg + " " + errorResponse
.getErrorMessage(), Toast.LENGTH_SHORT).show();
}
});
When user logs out call HyperTracking.stopMockTracking()
to stop tracking the user's location and activity. Refer here for more detail.
HyperTrack.stopMockTracking();
A user’s tracking session starts with HyperTrack.startTracking() and ends with HyperTrack.stopTracking(). In order to mock user movement developers would call HyperTrack.startMockTracking()
and HyperTrack.stopMockTracking()
respectively.
HyperTrack.startMockTracking()
API starts a simulation from the device's current location to a nearby place of interest within a 5-10km radius so the session is long enough to test your app & its features.
Developer can simulate user's location to a particular destination location from a given source location.
public static void startMockTracking(@NonNull LatLng sourceLatLng, @NonNull LatLng destinationLatLng, @Nullable HyperTrackCallback callback);
For detailed documentation of the APIs, customizations and what all you can build using HyperTrack, please visit the official docs.
Feel free to clone, use, and contribute back via pull requests. We'd love to see your pull requests - send them in! Please use the issues tracker to raise bug reports and feature requests.
We are excited to see what live location feature you build in your app using this project. Do ping us at [email protected] once you build one, and we would love to feature your app on our blog!
Join our Slack community for instant responses, or interact with our growing community. You can also email us at [email protected].