Add Map Api Key Programatically

Hi,

How can i add the Api Key to the map programatically? i tried the tutorial by adding MapProprieties but i get error could not load title 0/0/0 x0 something, ERROR 403. and the map is empty.

were you trying like on this tutorial Search along a route | Android Tutorials, Use Cases | Maps SDK for Android | TomTom Developer Portal ?

Yes this worked. Thank you! The error was in mapFragment = (MapFragment) getSupportFragmentManger.findFragmentById(R.id.mapFragment);

Map<ApiKeyType, String> mapKeys = new HashMap<>();
  mapKeys.put(ApiKeyType.MAPS_API_KEY,  " your api key ");

  MapProperties mapProperties = new MapProperties.Builder()
          .keys(mapKeys)
          .build();
  MapFragment mapFragment = MapFragment.newInstance(mapProperties);
  getSupportFragmentManager()
          .beginTransaction()
          .replace(R.id.mapFragment, mapFragment)
          .commit();
  //for fragment: getChildFragmentManager()
          .beginTransaction()
          .replace(R.id.mapFragment, mapFragment)
          .commit();
  mapFragment.getAsyncMap(this);