PackageManager.QueryIntentActivities() does not work?

Viewed 146

Documentation states that queryIntentActicities(Intent intent, int flags) is deprecated in API level 33, and to use this instead: https://developer.android.com/reference/android/content/pm/PackageManager#queryIntentActivities(android.content.Intent,%20android.content.pm.PackageManager.ResolveInfoFlags)

But when I use it, VS says

CS1061: 'PackageManager' does not contain a definition for 'ResolveInfoFlags' accepting a first argument of type 'PaclageManager' could be found

What am I missing?

Xamarin.Android (C#):

private bool IsThereAnAppToTakePictures()
        {
            Intent intent = new Intent(Android.Provider.MediaStore.ActionImageCapture);
            System.Collections.Generic.IList<ResolveInfo> availableActivities = ((int)Android.OS.Build.VERSION.SdkInt > 32) ? PackageManager.QueryIntentActivities(intent, PackageManager.ResolveInfoFlags) : 
                PackageManager.QueryIntentActivities(intent, PackageInfoFlags.MatchDefaultOnly);
            return availableActivities != null && availableActivities.Count > 0;
        }
2 Answers

You need to change syntax :

1.

PackageManager.MatchDefaultOnly to PackageManager.MATCH_DEFAULT_ONLY

2.

PackageManager.ResolveInfoFlags to PackageManager.GET_RESOLVED_FILTER

I have checked the official document and found that the ResolveInfoFlags was added into the class Android.Content.PM.PackageManager in the Android API 33.

So you need to set the Target Framework in your project as Android 13.0 Tiramisu if you want to use this.

I updated the Visual Studio to the last version 17.3.0 Preview 5.0, and then I can use it.

But I can't find a way to get the instance of it. I tried the following code:

var resolveInfoFlags = new PackageManager.ResolveInfoFlags()
// but there is no construction method without any parameters
Intent intent = new Intent(Android.Provider.MediaStore.ActionImageCapture);
System.Collections.Generic.IList<ResolveInfo> availableActivities = ((int)Android.OS.Build.VERSION.SdkInt > 32) ? PackageManager.QueryIntentActivities(intent, resolveInfoFlags) :
            PackageManager.QueryIntentActivities(intent, PackageInfoFlags.MatchDefaultOnly);

 and
  // the ResolveInfoFlags.Of(long value) will return a ResolveInfoFlags
  PackageManager.QueryIntentActivities(intent, Android.Content.PM.PackageManager.ResolveInfoFlags.Of(1234)) :
            PackageManager.QueryIntentActivities(intent, PackageInfoFlags.MatchDefaultOnly);
Related