Location Sharing (Android) Follow
This article describes how to implement location sharing using the Android SDK.
Location Sharing
Location sharing lets users share their location with each other.
Prerequisites
Location Sharing needs to be enabled by an admin in the Meridian Editor before you can use it in the SDK. If you’d like to enable Location Sharing, please email hpe-aruba-meridian@hpe.com.
If you haven’t already done so, you’ll need to generate a valid token in the Editor. To generate one, in the sidebar menu click Permissions, and then click Application Tokens. Click Add Application + to generate a token for your app. You can name it anything.
When configuring the Meridian SDK, set the application token you generated in the Editor:
LocationSharing.init("kd84hf83ck93k39dyi3nxo3mf94");
For best results, call init
from your Application class.
LocationSharing
LocationSharing
is the main access point to the Location Sharing API. Use the User
, Friend
, Invite
, and Location
classes to get the Location Sharing data.
Create Accounts
// Creates a location sharing user. All users require a first name. Last name is optional. User sampleUser = new User(); sampleUser.setFirstName("Sample User"); LocationSharing.shared().createUser(sampleUser, new LocationSharing.Callback() { @Override public void onSuccess(User user) { // ... } @Override public void onError(LocationSharingException t) { // ... } });
Start Location Sharing
LocationSharing.shared().startPostingLocationUpdates(applicationContext);
Stop Location Sharing
LocationSharing.shared().stopPostingLocationUpdates(applicationContext);
Check Location Sharing Status
LocationSharing.shared().isUploadingServiceRunning() // example: button that performs start and stop sharing location if (LocationSharing.shared().isUploadingServiceRunning()) { LocationSharing.shared().stopPostingLocationUpdates(applicationContext); } else { LocationSharing.shared().startPostingLocationUpdates(applicationContext); }
Start and Stop Location Sharing Listener
LocationSharing.shared().addListener(new LocationSharing.Listener() { @Override public void onPostingLocationUpdatesStarted() { // ... } @Override public void onFriendsUpdated(List friends) { // ... } @Override public void onPostingLocationUpdatesStopped() { // ... } });
Create an Invite
Invitations expire after 7 days.
LocationSharing.shared().createInvite(new LocationSharing.Callback() { @Override public void onSuccess(Invite invite) { // ... // At this point, you can share the invite url. (invite.getShareUrl()) } @Override public void onError(LocationSharingException e) { // ... } });
Get the Current Friend List
LocationSharing.shared().getFriends(new LocationSharing.Callback() { @Override public void onSuccess(List friendsList) { // ... } @Override public void onError(LocationSharingException e) { // ... } });
createInvite and getFriends
LocationSharing
keeps a copy of the current user, for use by calls like createInvite
and getFriends
. The implementor is responsible for storing the current user and setting it to the LocationSharing
object.
When an account is created, the new user is automatically set to the current user.
Store the New User
After creating the new user, store it:
LocationSharing.shared().createUser(newUser, new LocationSharing.Callback() { @Override public void onSuccess(User user) { OurOwnStorage.save(newUser); } @Override public void onError(LocationSharingException t) { // ... } });
Set the Current User
If a user restarts the app, the current user needs to be set again. This is equivalent to a login operation.
LocationSharing.shared().setCurrentUser(OurOwnStorage.retrieveLocationSharingUser());
Comments
0 comments
Please sign in to leave a comment.