0

I want to show pdf file after downloading (from Internal Storage Custom folder) in my app. I want users can choice their preferred apps to open it. I have used the below mention code but it is not working. How can I do this? enter image description here

string fileName = "qdummy.pdf";
Android.Net.Uri uri = Android.Net.Uri.Parse("file:///storage/emulated/0/TESTFOLDER/" + fileName);
Intent intent = new Intent(Intent.ActionView);
intent.SetDataAndType(uri, "application/pdf");
intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);

try
{
    Application.Context.StartActivity(intent);
}
catch (Exception)
{
    Toast.MakeText(Application.Context, "No hay aplicacion instalada para ver PDF", ToastLength.Long).Show();
} 
Robert
  • 2,407
  • 1
  • 24
  • 35
Soumen Halder
  • 117
  • 1
  • 13

1 Answers1

0

issue reolved by,

try
                    {
                        string extension = MimeTypeMap.GetFileExtensionFromUrl(Android.Net.Uri.FromFile(file).ToString());
                        string mimeType = MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension);
                        Intent intent = new Intent(Intent.ActionView);
                        intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);
                        Android.Net.Uri path = FileProvider.GetUriForFile(Application.Context, Android.App.Application.Context.PackageName + ".provider", file);
                        intent.SetDataAndType(path, mimeType);
                        intent.AddFlags(ActivityFlags.GrantReadUriPermission);
                        Application.Context.StartActivity(Intent.CreateChooser(intent, "Choose App"));
                    }
                    catch (Exception ex)
                    {
                        Toast.MakeText(Application.Context, "problem", ToastLength.Long).Show();
                    }
Soumen Halder
  • 117
  • 1
  • 13