open local pdf file Android

  

I’m downloading a pdf file to the Downloads folder to view. For iOS and Win32 this is easy because the TWebBrowser handles pdf files fine. My problem is with Android. Below is my code:

if (FileExists(LFileName)) // pdf file is there
{
#if defined(_PLAT_IOS) || defined(_PLAT_MSWINDOWS)
Form1->WebBrowser1->URL = “file://” + LFileName;
Form1->WebBrowser1->Visible = true;
#endif

#if defined(_PLAT_ANDROID)
Androidapi::Jni::Graphicscontentviewtext::_di_JIntent intent =
TJIntent::Create();
intent->setDataAndType(StringToJString(“file://” + System::Ioutils::TPath::Combine(System::Ioutils::TPath::GetSharedDownloadsPath(), LFileName)), StringToJString(L”application/pdf”));
intent->setAction(TJIntent::JavaClass->ACTION_VIEW);
if (SharedActivity()->getPackageManager()->queryIntentActivities(intent, TJPackageManager::JavaClass->MATCH_DEFAULT_ONLY)->size() > 0) {
SharedActivity()->startActivity(intent);
} else {
ShowMessage(“PDF viewer not found”);
}
#endif
}

When i run it on an Android it opens Adobe PDF viewer but does not open the file.

I’m guessing that i’m not passing the pdf filename properly. Any ideas?

EDIT: Ok, use of file:// is deprecated and it looks like only way to go is via FileProvider – per this SE question. Miles of hard road for someone at my level. I just want to display a pdf.

thanks,
russ

Comments are closed.