Get version number / name of MvxApplication

Is there a way to get the version number and version name in MvxApplication automatically or should we code it for each platform?

+3


source to share


2 answers


I don't see an existing plugin for getting cross platform version numbers of apps, but it's not that hard to write.

Here's how to get the current version number for each platform. I'm sure you can write similar code to get the build number and app name.

Windows Phone

public static string GetVersion()
{
    var versionAttribute = Assembly.GetExecutingAssembly()
        .GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true)
        .FirstOrDefault() as AssemblyFileVersionAttribute;

    return versionAttribute != null ? versionAttribute.Version : "";
}

      



Android

public static string GetVersion()
{
    var context = Application.Context;
    var info = context.PackageManager.GetPackageInfo(context.PackageName, 0);
    return info.VersionName;
}

      

IOS

public static string GetVersion()
{
    NSObject version = NSBundle.MainBundle.InfoDictionary["CFBundleShortVersionString"];
    return version.ToString();
}

      

+4


source


More about android:



public class InfoService : IInfoService
{
    public string DeviceId
    {
        get
        {                
            return Settings.Secure.GetString(Application.Context.ContentResolver, Settings.Secure.AndroidId);
        }
    }

    public string PackageName
    {
        get
        {
            return Application.Context.PackageName;
        }
    }

    public string AppVersionName
    {
        get
        {
            var context = Application.Context;
            var info = context.PackageManager.GetPackageInfo(context.PackageName, 0);

            return info.VersionName;
        }
    }

    public int AppVersionCode
    {
        get
        {
            var context = Application.Context;
            var info = context.PackageManager.GetPackageInfo(context.PackageName, 0);

            return info.VersionCode;
        }
    }

    public double DeviceScreenWidth
    {
        get
        {
            var context = Application.Context;
            var displayMetrics = context.Resources.DisplayMetrics;

            return displayMetrics.WidthPixels / displayMetrics.Density;
        }
    }

    public double DeviceScreenHeight
    {
        get
        {
            var context = Application.Context;
            var displayMetrics = context.Resources.DisplayMetrics;

            return displayMetrics.HeightPixels / displayMetrics.Density;
        }
    }
}

      

+1


source







All Articles