Search code examples
google-mapsxamarin.formsxamarin.android

Xamarin forms android - google maps app not found


I have an XF android app that checks if the Google Maps app is installed on device.

Before Android 11 I used this code:

 public static bool IsAppInstalled(string packageName)
 {
      PackageManager pm = MainActivity.AppInstance.PackageManager;
      bool installed;
      try
      {
          pm.GetPackageInfo(packageName, PackageInfoFlags.Activities);
          installed = true;
      }
      catch (PackageManager.NameNotFoundException)
      {
          installed = false;
      }
          return installed;
      }
  }

with packageName == "com.google.android.apps.maps".

Now I'm testing it on a Samsung Galaxy S10 with Android 11 and with Google Maps installed as stock app, and the above function return false.

How can I check if that app is installed on the device?

I have tried also this solution but without luck.

Thank you.


Solution

  • Since Android 11 (API level 30), most user-installed apps are not visible by default. In your manifest, you must statically declare which apps you are going to get info about, as in the following:

    <manifest package="com.example.game">
        <queries>
            <package android:name="com.example.store" />
            <package android:name="com.example.services" />
        </queries>
        ...
    </manifest>
    

    In the rare cases where the <queries> element doesn't provide adequate package visibility, you can use the QUERY_ALL_PACKAGES permission.

    For more details,please check:

    https://developer.android.com/training/package-visibility

    https://medium.com/androiddevelopers/package-visibility-in-android-11-cc857f221cd9