I have an Android project, and I wish to store my API keys in my Android Manifest file. To read them, I can read the bundle that comes through in the OnCreate
override in my MainActivity
class: viz
type MainActivity () =
inherit FormsApplicationActivity()
static let [<Literal>] MyApiKey = "my-api-key"
override this.OnCreate (bundle) =
base.OnCreate(bundle)
let createViewModel() = new PhotoSetViewModel() :> IRoutableViewModel
AppDomain.CurrentDomain.UnhandledException.AddHandler(UnhandledExceptionEventHandler(AppExceptions.processException))
Forms.Init(this, bundle)
Xamarin.FormsMaps.Init(this, bundle)
// Read the API key that I've stored in AndroidManifest.xml
let platform = new DroidPlatform(bundle.GetString(MyApiKey)) :> ICustomPlatform
let app = new App<ICustomPlatform>(platform, new UiContext(this), createViewModel)
app.Init()
base.LoadApplication app
There is one small problem. bundle
is always null. This is happening in all of my projects, in both C# and F# implementations.
I'm using the Xamarin.Forms NuGet package, Version 2.3.4.224.
Instead of trying to use the bundle
argument, it is possible to retrieve the metadata as follows:
let metaData = PackageManager.GetApplicationInfo(PackageName, PackageInfoFlags.MetaData).MetaData
let platform = new DroidPlatform(metaData.GetString(MyApiKey)) :> ICustomPlatform
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.