Roam.ai Docs
HomeContactDashboard
  • Introduction
  • Getting Started
    • Key Concepts
  • Frameworks
  • Android
    • Quickstart (Android)
    • Pub/Sub Locations (Android)
    • SDK Methods (Android)
      • SDK Configuration (Android)
      • Get Current Location (Android)
      • Update Current Location (Android)
      • Update Location When Stationary (Android)
      • Trip v1 SDK Methods (Android)
      • Trip v2 SDK Methods (Android)
        • Create Trip (Android)
        • Update Trip (Android)
        • Start Quick Trip (Android)
        • Start Trip (Android)
        • End Trip (Android)
        • Pause Trip (Android)
        • Resume Trip (Android)
        • Sync Trip (Android)
        • Get Trip (Android)
        • Get Active Trips (Android)
        • Get Trip Summary (Android)
        • Subscribe to Trip (Android)
        • Delete Trip (Android)
    • Utility Methods (Android)
    • Troubleshooting (Android)
    • Changelog (Android)
  • iOS
    • Quickstart (iOS)
    • Pub/Sub Locations (iOS)
    • SDK Methods (iOS)
      • SDK Configuration (iOS)
      • Get Current Location (iOS)
      • Update Current Location (iOS)
      • Update Location When Stationary (iOS)
      • Trips v1 SDK Methods (iOS)
      • Trips v2 SDK Methods (iOS)
        • Create Trip (iOS)
        • Update Trip (iOS)
        • Start Quick Trip (iOS)
        • Start Trip (iOS)
        • End Trip (iOS)
        • Pause Trip (iOS)
        • Resume Trip (iOS)
        • Sync Trip (iOS)
        • Get Trip (iOS)
        • Get Active Trips (iOS)
        • Get Trip Summary (iOS)
        • Subscribe Trip (iOS)
        • Delete Trip (iOS)
    • Utility Methods (iOS)
    • Troubleshooting (iOS)
    • Changelog (iOS)
  • React Native
  • Flutter
  • PRODUCTS
  • Tracking (BETA)
  • Geofencing
  • Trips
  • APIs
    • Authorization
    • Users API
      • Create User API
      • Get User API
      • Update User API
    • Locations API
      • Get Locations API
      • Get Stop Locations API
    • Insights API
      • Get User POIs API
      • Get User Home Location API
      • Get User Work Location API
    • Trips v1 API
      • Create Trip API v1
      • Get Trip API
      • Update Trip API v1
      • Delete Trip API v1
      • Trip Summary API
      • Export Trip Summary as GPX
    • Trips v2 API
      • Create Trip API
      • Get Single Trip API
      • Get Multiple Trips API
      • Update Trip API
      • Control Trip API
        • Start Trip API
        • Pause Trip API
        • Resume Trip API
        • End Trip API
      • Get Trip Summary API
      • Export Trip API
      • Delete Trip API
    • Geofencing API
      • CREATE Geofence API
      • GET Geofence API
      • UPDATE Geofence API
      • DELETE Geofence API
    • Events API
      • Get Events
      • Trip Events
    • Nearby API
      • Get Nearby User API
      • Get Nearby Geofence API
    • Moving Geofence API
      • Create Moving-Geofence API
      • Update Moving-Geofence API
      • GET Moving-Geofence API
      • Delete Moving-Geofence API
    • User Groups API
      • Create Group API
      • Get User Group by ID
      • Get User Group List
      • Add Users to Group API
      • Update Group API
      • Find Nearby Users from Group
    • Query with Metadata
  • WEBHOOK
    • Webhook
    • Slack Integration
  • LIBRARIES
    • Javascript Library
    • Go Library
    • Python Library
Powered by GitBook
On this page
  • Set Device Token
  • Get Device Token
  • Check location permission
  • Check Location Services
  • Check Background Location Permission
  • Request Location Permissions
  • Request Location Services
  • Request Background Location Permission
  • Check Location Tracking
  • Update Current Location
  • Logout
  • Notification Opened Handler
  • Disable Battery Optimization (android 6+)
  • Check Battery Optimization

Was this helpful?

Export as PDF
  1. Android

Utility Methods (Android)

Explore the Android utility methods related to location permissions.

PreviousDelete Trip (Android)NextTroubleshooting (Android)

Last updated 2 years ago

Was this helpful?

Set Device Token

The Roam SDK is capable of sending push notifications to your users. to get the device token.

Roam.setDeviceToken("FCM DeviceToken")
Roam.setDeviceToken("FCM DeviceToken");

Get Device Token

This method gets the FCM DeviceToken from the SDK.

Roam.getDeviceToken()
Roam.getDeviceToken();

Check location permission

Check whether your app has location permission. Returns a boolean, which is true if location permission has been granted or false otherwise.

Roam.checkLocationPermission()
Roam.checkLocationPermission();

Check Location Services

Check if the device has location services enabled. This method returns a boolean, which is true if the location services are on and false otherwise.

Roam.checkLocationServices()
Roam.checkLocationServices();

Check Background Location Permission

This utility method checks whether your app has background location permissions. It returns a boolean as true if background location permission has been granted, or false otherwise.

Roam.checkBackgroundLocationPermission()
Roam.checkBackgroundLocationPermission();

Request Location Permissions

Call this method to request the user to enable location permissions.

Roam.requestLocationPermission(this)
Roam.requestLocationPermission(this);
override fun onRequestPermissionsResult(requestCode: Int, permissions:
    Array<String>, grantResults:IntArray) {
        when (requestCode) {
            Roam.REQUEST_CODE_LOCATION_PERMISSION->
            if (grantResults[0] ==PackageManager.PERMISSION_GRANTED) {
            ....
            } else if (grantResults[0] ==PackageManager.PERMISSION_DENIED) {
            ....
            }
        }
}
//Callback from request location permission method.
@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
   switch (requestCode) {
      case Roam.REQUEST_CODE_LOCATION_PERMISSION:
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            ...
         } else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
            ...   
         }
      break;
   }
}

Request Location Services

Call this method to enable location services.

Roam.requestLocationServices(this)
Roam.requestLocationServices(this);
 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
      super.onActivityResult(requestCode, resultCode, data)
      if (requestCode == Roam.REQUEST_CODE_LOCATION_ENABLED) {
            ....
      }
}
//Callback from request location services method.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   if (requestCode == Roam.REQUEST_CODE_LOCATION_ENABLED) {
   }
}

Request Background Location Permission

Call this method to request the user to enable background location permissions.

Roam.requestBackgroundLocationPermission(this)
Roam.requestBackgroundLocationPermission(this);
override fun onRequestPermissionsResult(requestCode: Int, permissions:
Array<String>, grantResults: IntArray) {
    when (requestCode) {
    Roam.REQUEST_CODE_BACKGROUND_LOCATION_PERMISSION->
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            ...
        } 
        else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {
            ...
        }
    }
}
//Callback from request background location permission method.
@Override
public void onRequestPermissionsResult(intrequestCode, Stringpermissions[],
int[] grantResults) {
    switch (requestCode) {
        case Roam.REQUEST_CODE_BACKGROUND_LOCATION_PERMISSION:
        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {  
               ...      
        } 
        else if (grantResults[0] == PackageManager.PERMISSION_DENIED) {         
                ...        
        }
        break;   
    }
}

Check Location Tracking

Check whether location tracking has been started or not. This method returns a boolean value.

Roam.isLocationTracking()
Roam.isLocationTracking();

Update Current Location

Using the updateCurrentLocation method, you can update the user's current location and set the accuracy ranging from 10 to 100 meters (default is 10).

Roam.updateCurrentLocation(DesiredAccuracy, accuracy)
Roam.updateCurrentLocation(DesiredAccuracy, accuracy);

This method should be used only if you need to update the current location of the device with better accuracy. Using this method consistently will consume more battery.

The higher the accuracy, the longer the response time. In some cases, it can take up to 30 seconds depending on the GPS signal strength.

Parameter

Description

DesiredAccuracy

RoamTrackingMode.DesiredAccuracy.HIGH or RoamTrackingMode.DesiredAccuracy.MEDIUM or RoamTrackingMode.DesiredAccuracy.LOW

Logout

Logout from Roam SDK using the logout() method.

NOTE - You need to reinitialize the SDK to login again.

Roam.logout(object : RoamLogoutCallback {
        override fun onSuccess(message: String) {
                
        }
        override fun onFailure(roamError: RoamError) {
                // Access Error code and message here
                // roamError.code
                // roamError.message
        }
})
Roam.logout(new RoamLogoutCallback() {
      @Override
      public void onSuccess(String message) {

      }

      @Override
      public void onFailure(RoamError roamError) {
                // Access Error code and message here
                // roamError.code;
                // roamError.message;
      }
});

Notification Opened Handler

By using this method inside FirebaseMessagingService class, track the campaign impressions and counts.

override fun onMessageReceived(RemoteMessage remoteMessage) {
  super.onMessageReceived(remoteMessage)
  val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as
        NotificationManager
  ....
  intent.putExtra(Roam.EXTRA, Roam.notificationReceiveHandler(remoteMessage.getData()))
  ....
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
   super.onMessageReceived(remoteMessage);
   NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
   ...
   intent.putExtra(Roam.EXTRA, Roam.notificationReceiveHandler(remoteMessage.getData()));
   ...
   notificationManager.notify(NotificationID, builder.build());
}
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
      ....
    Roam.notificationOpenedHandler(intent)
)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    Roam.notificationOpenedHandler(getIntent());
}

Disable Battery Optimization (android 6+)

When running the SDK on Android 6 (and higher), it is recommended to ask the user to disable battery optimization for your application. This ensures that location tracking continues to work when the device is in Doze mode.

After explaining the benefits of disabling battery optimization, call the disableBatteryOptimization() method of the Roam class.

Roam.disableBatteryOptimization()
Roam.disableBatteryOptimization();

This will trigger a system dialog asking the user to allow disabling battery optimization for your app.

Check Battery Optimization

Roam.isBatteryOptimizationEnabled()
Roam.isBatteryOptimizationEnabled();

Moreover, on Android Pie, disabling battery optimization prevents Adaptive Battery from your app based on usage and , which can impact the detection quality of the SDK.

Add Firebase to your Android project
bucketing
restricting background processing