AndroidSupportComponents icon indicating copy to clipboard operation
AndroidSupportComponents copied to clipboard

Application.Context not found / getting android version information

Open dooferorg opened this issue 3 years ago • 0 comments

Xamarin.Android Version (eg: 6.0):

Targeting Android 12, minimum is Android 8. Visual Studio 2022

Operating System & Version (eg: Mac OSX 10.11):

Windows 10

Support Libraries Version (eg: 23.3.0):

28.0.0.3 (All of the Xamarin.Android.Support.* nuget packages of that version). Xamarin.AndroidX.Legacy.Support.V4 10.0.12 is also installed

Describe your Issue:

I am have difficulty with the transition to the support libraries. Mostly everything worked but the usual way to get the version information of the package build isn't working. The required Application.Context is not present.

Is there an alternative method to getting the version information that I need since i cannot use the Android.App libraries any more?

Steps to Reproduce (with link to sample solution if possible):

Using the snippet below to get the version information worked before transitioning to the support framework.

Context context = Application.Context;
            string VersionNumber = context.PackageManager.GetPackageInfo(context.PackageName, PackageInfoFlags.MetaData).VersionName;
            string BuildNumber = context.PackageManager.GetPackageInfo(context.PackageName, PackageInfoFlags.MetaData).VersionCode.ToString();

Include any relevant Exception Stack traces, build logs, adb logs:

dooferorg avatar Jul 15 '22 13:07 dooferorg