0

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?

RMR
  • 599
  • 3
  • 12
  • 35
  • You have to know the other app's URL scheme, pre-register the scheme in your app's info.plist and and then you can call `CanOpenUrl` to determine if the user has that app installed : https://developer.apple.com/reference/uikit/uiapplication/1622952-canopenurl There is no direct equivalence of obtaining all the installed package ids as that is not allowed within iOS. – SushiHangover Oct 03 '16 at 09:35
  • You are true. kindly check below link http://stackoverflow.com/questions/3808691/detecting-programmatically-whether-an-app-is-installed-on-iphone but problem is how to use this method in xamarin forms? how to define own URL handlers in Info.plist file? – RMR Oct 03 '16 at 10:12
  • 1
    http://stackoverflow.com/questions/39781475/xamarin-forms-maps-is-possible-to-call-google-maps-from-a-button/39782171#39782171 – SushiHangover Oct 03 '16 at 10:15
  • Thanks, Its really helps me but I don't understand what is "comgooglemaps-x-callback://". is it bundle name? I have also tried update info.plist file with the help of following link http://stackoverflow.com/questions/3512228/how-to-check-programatically-if-an-app-is-installed but it didn't work. (Always false as a return value) – RMR Oct 05 '16 at 06:46
  • 1
    It is one of the iOS URL schemes that google registers for the Map app : https://developers.google.com/maps/documentation/ios-sdk/urlscheme and also check out the following for Map's `LSApplicationQueriesSchemes` for updating your app's `info.plist` : https://developers.google.com/maps/documentation/ios-sdk/start#step_7_declare_the_url_schemes_used_by_the_api – SushiHangover Oct 05 '16 at 06:50

0 Answers0