I want to find some particular Application is already installed or not in xamarin forms (I want to implement in android and ios).
If app is not installed in device then "Install" button is enabled. On Install button click event directly itunes should be open. I also want to search version number.
I have achieved same functionality for android in xamarin forms but I need help for ios.
My android code :
public class IsAppInstalled : IIsAppInstalled
{
public string AppVersion { get; set; }
public void NavigatePage(string Package_Name)
{
try
{
var intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse("market://details?id=" + Package_Name));
// we need to add this, because the activity is in a new context.
// Otherwise the runtime will block the execution and throw an exception
intent.AddFlags(ActivityFlags.NewTask);
Application.Context.StartActivity(intent);
}
catch (ActivityNotFoundException)
{
var intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse("http://play.google.com/store/apps/details?id=" + Package_Name));
// we need to add this, because the activity is in a new context.
// Otherwise the runtime will block the execution and throw an exception
intent.AddFlags(ActivityFlags.NewTask);
Application.Context.StartActivity(intent);
}
}
bool IIsAppInstalled.IsAppInstalled(string Appname)
{
bool IsInstallflag = false;
var flag = PackageInfoFlags.Activities;
var apps = Application.Context.PackageManager.GetInstalledApplications(flag);
try
{
foreach (var app in apps)
{
var appInfo = Application.Context.PackageManager.GetApplicationInfo(app.PackageName, 0);
var appLabel = Application.Context.PackageManager.GetApplicationLabel(appInfo);
var versionNumber = Application.Context.PackageManager.GetPackageInfo(app.PackageName, 0).VersionName;
//var appVersion=Application.Context.PackageManager.
if (appLabel.ToLower().Contains(Appname.ToLower()))
{
//var builder = new AlertDialog.Builder(this);
//builder.SetTitle("Found it!");
//builder.SetMessage(appLabel + " installed at: " + app.SourceDir);
//builder.Show();
IsInstallflag = true;
//MyVersionName(versionNumber);
AppVersion = versionNumber;
break;
}
}
return IsInstallflag;
}
catch (PackageManager.NameNotFoundException e)
{
return IsInstallflag;
}
}
}
I have used these classes using dependency injection. This code is perfectly work.
How to implement same functionality for ios in xamarin forms?