Am trying to get my app to display the file picker interface programatically on button click but when i click on that button, my app crashes... The button has the label "open" and its supposed to filter files and display only files with the extension ".txt",Here is the code of the method that am trying to achieve that with...
private void Button2_Click(object sender, EventArgs e)
{
//Program this button to open a file picker interface
Intent intent = new Intent(BaseContext, FilesDir.Class);
intent.PutExtra(FilesDir.AbsolutePath, true);
StartActivityForResult(intent,1);
}
I used java code as blueprint to achieve this but it seems there are some huge difference lines between these two approaches of android programming, Your help is greatly appreciated.... Additional code to help the intent filter for text files only is also greatly welcome too
Have a try with codes below:
Intent intent = new Intent();
intent.SetType("text/plain");
intent.SetAction(Intent.ActionGetContent);
StartActivityForResult(Intent.CreateChooser(intent, "Select file"), 1);
If you have java code, just update them in the question and I can help you to translate them to C#.
Refer: how-to-open-pdf-or-txt-file-in-default-app-on-xamarin-forms