0

I will explain my situation.

I'm working on a taxi application that consumes a lot of the google map service, so in order to reduce costs we decided to use 6 different ApiKeys that rotate throughout the month. These ApiKeys are received by my app through a service that tells me which ApiKey to use when it starts.

The problem appears when I can't find a way to change the apiKey because the only way to assign it is through a constant and It became imposible.

I´m Currently using

In my app I´ve a class where I declare my ApiKey but I need it not to be a constant, but it simply wont let me use a normal variable.

    public class AppConstants
    {
        //I would Like not to use a constant to declare the ApiKey and get it through a service
        public const string GoogleMapsApiKey = "MyApiKey";
    } 

Here es my "MainApplication" on Android Project where I´ve to declare the ApiKey

    //Is there another way to declare the Api key here?
    [MetaData("com.google.android.maps.v2.API_KEY",Value = AAppConstants.GoogleMapsApiKey)]
    [Application(Theme = "@style/MainTheme")]

    public class MainApplication : Application
    {
        public MainApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer) {}

        public override void OnCreate()
        {
            base.OnCreate();
            Xamarin.Essentials.Platform.Init(this);
            //More code
        }
    }

My main goal is just assign an ApiKey Just once each time the user initialize the app, not just one time and keep the ApiKey for ever. If anybody can help me I would be so grateful

(Sorry for my bad English, please ask me if you couldn´t understand something, I will explain it with pleasure)

0 Answers0