gpt4 book ai didi

c# - Xamarin 表单(Android): OnCreate bundle is null

转载 作者:太空狗 更新时间:2023-10-29 14:43:47 25 4
gpt4 key购买 nike

我有一个 Android 项目,我希望将我的 API key 存储在我的 Android list 文件中。要阅读它们,我可以阅读在我的 MainActivity 类中的 OnCreate 覆盖中通过的包:即

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 始终为空。这发生在我的所有项目中,包括 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

关于c# - Xamarin 表单(Android): OnCreate bundle is null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43275322/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com