I need to display the app's build version in my settings page.
So how can i get the versionCode
and versionName
from AndroidManifest.xml
file programmatically.
Or
Is there any way to get the build version programmatically in xamarin.forms
.
Once in Settings, tap Apps and notifications (or your phone manufacturer's name it). When you're in there, tap See all xyz apps (where xyz is the number of apps you have installed). Now scroll down until you find the app you want to find the version for. Then tap it in the list.
You can find the version of your Xamarin plug-ins for Visual Studio by going to "Help" -> "About Microsoft Visual Studio" in VS, and scrolling down to the Xamarin plug-ins.
Ultimately, the Android version number refers to full updates like Android 11 and 12, while the build number gets into the specifics of when your phone was updated and the software version onboard.
For version name:
Application.Context.ApplicationContext.PackageManager.GetPackageInfo(Application.Context.ApplicationContext.PackageName, 0).VersionName
For version code:
Application.Context.ApplicationContext.PackageManager.GetPackageInfo(Application.Context.ApplicationContext.PackageName, 0).VersionCode
With a Dependency service:
For iOS:
using Foundation; [assembly: Xamarin.Forms.Dependency(typeof(Screen_iOS))] namespace XXX.iOS { public class Screen_iOS : IScreen { public string Version { get { NSObject ver = NSBundle.MainBundle.InfoDictionary["CFBundleShortVersionString"]; return ver.ToString(); } } } }
For Android:
using Xamarin.Forms; [assembly: Dependency(typeof(ScreenAndroid))] namespace XXX.Droid { class ScreenAndroid : Java.Lang.Object, IScreen { public string Version { get { var context = Forms.Context; return context.PackageManager.GetPackageInfo(context.PackageName, 0).VersionName; } } } }
And the interface:
interface IScreen { string Version { get; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With