mapbox / mapbox-gl-native-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
218 stars 116 forks source link

Change MAPBOX_ACCESS_TOKEN on runtime #718

Open taq opened 2 years ago

taq commented 2 years ago

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 commented 2 years ago

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))