[英]Xamarin Forms (Android): OnCreate bundle is null
我有一個Android項目,我希望將我的API密鑰存儲在我的Android Manifest文件中。 要閱讀它們,我可以在MainActivity
類中讀取OnCreate
覆蓋中出現的包: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
有一個小問題。 bundle
總是為null。 這在我的所有項目中都發生,包括C#和F#實現。
我正在使用Xamarin.Forms NuGet包,版本2.3.4.224。
可以按如下方式檢索元數據,而不是嘗試使用bundle
參數:
let metaData = PackageManager.GetApplicationInfo(PackageName, PackageInfoFlags.MetaData).MetaData
let platform = new DroidPlatform(metaData.GetString(MyApiKey)) :> ICustomPlatform
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.