Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current app's build version - Xamarin.Android

Tags:

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.

like image 934
Tushar patel Avatar asked Sep 23 '16 11:09

Tushar patel


People also ask

How do you find the version of an app on Android?

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.

How do I find my xamarin version?

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.

What is build version in Android?

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.


2 Answers

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 
like image 198
Parth Patel Avatar answered Sep 29 '22 06:09

Parth Patel


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; } } 
like image 28
Mario Galván Avatar answered Sep 29 '22 06:09

Mario Galván