Search code examples
mauimaui-blazormaui-community-toolkit

How to check an App is installed or not using MAUI App?


Need to check one App is installed or not. Tried with below code, but its not working in .net MAUI App. Any alternate solution?

    [Obsolete]
    private bool isAppInstalled(String packageName)
    {

        PackageManager pm = this.PackageManager;

        bool installed = false;
        try
        {
            pm.GetPackageInfo(packageName, PackageInfoFlags.Activities);
            installed = true;

        }
        catch (Exception e)
        {
            installed = false;
        }
        return installed;
    }

Eg: trying to check Google Pay is installed or not:

  Boolean result = isAppInstalled("com.google.android.apps.nbu.paisa.user");

Its always return false, even if the app is installed.


Solution

  • Add <queries> tag for the app package you want check in the \Platforms\Android\AndroidManifest. Such as:

    <manifest>
        <queries>
            <package android:name="com.google.android.apps.nbu.paisa.user"/>
        </queries>