Skip to content

Location tracking

This article shows how to configure location tracking for your Android or FireOS application.

Add at least one of the following permissions to your AndroidManifest.xml file to declare your app’s intent to collect location data:

1
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
1
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

ACCESS_FINE_LOCATION includes GPS data in reporting user location while ACCESS_COARSE_LOCATION includes data from the most battery-efficient non-GPS provider available (for example, the network). Coarse location will likely be sufficient for most location data use-cases; however, under the runtime permissions model, receiving location permission from the user implicitly authorizes the collection of fine location data. Take a look at Location Strategies from Android Developers to read more about the differences between these location permissions and how you should use them.

Disabling automatic location tracking

Compile-time Option

To disable automatic location tracking at compile time, set com_braze_enable_location_collection to false in braze.xml:

1
<bool name="com_braze_enable_location_collection">false</bool>

Runtime Option

To selectively disable automatic location tracking at runtime, use BrazeConfig:

1
2
3
4
BrazeConfig brazeConfig = new BrazeConfig.Builder()
  .setIsLocationCollectionEnabled(false)
  .build();
Braze.configure(this, brazeConfig);
1
2
3
4
val brazeConfig = BrazeConfig.Builder()
    .setIsLocationCollectionEnabled(false)
    .build()
Braze.configure(this, brazeConfig)

Manually Logging Location

Even when automatic tracking is disabled, you can manually log single location data points via the setLastKnownLocation() method on BrazeUser like this:

1
2
3
4
5
6
Braze.getInstance(context).getCurrentUser(new IValueCallback<BrazeUser>() {
  @Override
  public void onSuccess(BrazeUser brazeUser) {
    brazeUser.setLastKnownLocation(LATITUDE_DOUBLE_VALUE, LONGITUDE_DOUBLE_VALUE, ALTITUDE_DOUBLE_VALUE, ACCURACY_DOUBLE_VALUE);
  }
}
1
2
3
Braze.getInstance(context).getCurrentUser { brazeUser ->
  brazeUser.setLastKnownLocation(LATITUDE_DOUBLE_VALUE, LONGITUDE_DOUBLE_VALUE, ALTITUDE_DOUBLE_VALUE, ACCURACY_DOUBLE_VALUE)
}
HOW HELPFUL WAS THIS PAGE?
New Stuff!