我想找到一些特定的应用程序已经安装或者没有安装在xamarin表单中(我想在android和ios中实现)。
如果设备中未安装应用程序,则启用“安装”按钮。在安装按钮单击事件直接itunes应该打开。我也想搜索版本号。
我已经在xamarin表单中获得了相同的android功能但是我需要ios的帮助。
我的安卓代码:
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;
}
}
}
我使用依赖注入使用了这些类。这段代码完美无缺。
如何在xamarin表单中为ios实现相同的功能?