FilePicker.PickAsync(PickOptions.Default) does always fail, how to fix it?

xi guo 40 Reputation points
2023-08-23T19:56:00.8766667+00:00

using Xamarin.Essentials;

already:

  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

When I try this:

            try
			{                 
				await FilePicker.PickAsync(PickOptions.Default);             
			}             
			catch (Exception ex)             
			{                 
				Console.WriteLine(ex.ToString());             
			}

I receive the exceptions:

The current Activity can not be detected. Ensure that you have called Init in your Activity or Application class

Help!

Thanks!

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,377 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.