mapbox-gl-native-android icon indicating copy to clipboard operation
mapbox-gl-native-android copied to clipboard

Change MAPBOX_ACCESS_TOKEN on runtime

Open taq opened this issue 2 years ago • 1 comments

Hi!

As said on every doc about installation, we need to set MAPBOX_ACCESS_TOKEN on our build.gradle file, loading it from properties, ok ... but I need to change the token for a specific customer token, after the login process, is it possible? While writing this I found a reference to setAccessToken, maybe is the right way? Is there any examples to use it with Kotlin on V10? Thanks!

taq avatar Nov 04 '21 16:11 taq

I think I figured it out with V10:

https://docs.mapbox.com/android/maps/guides/migrate-to-v10/#default-resourceoptions-configurationincluding-access-token

// Set the application-scoped ResourceOptionsManager with customised token and tile store usage mode
// so that all MapViews created with default config will apply these settings.
ResourceOptionsManager.getDefault(this, getString(R.string.mapbox_access_token)).update {
  tileStoreUsageMode(TileStoreUsageMode.READ_ONLY)
}

I just was thinking that setDefault would be a better name (write to the defaults), but anyway, this way, as stated all resources (maps, routes) after that will use that specific token, right? Even if I use only:

ResourceOptionsManager.getDefault(this, getString(R.string.mapbox_access_token))

taq avatar Nov 05 '21 11:11 taq