Open a local pdf file from Delphi Firemonkey Code for Android App [duplicate]

  

This question already has an answer here:

Delphi open PDF from ios/Android local storage

2 answers

NOTE: Delphi XE8, Firemonkey App for Android 4.4.2

I am trying to open a pdf document from Android App made with Firemonkey and only open the Adobe Acrobat, but the file doesn’t, then I have found online in several webpages and I have tried every one of them, but no one works.

The error message is

Adobe can’t find the document to open

But the document is in a public folder, and I have moved it for differents folder and nothing happend.

I have opened images from other folders without problem, I don’t understand.

Can anybody give me a solution please?.

procedure TForm1.bttnAbrirClick(Sender: TObject);
var
NombreFichero,
RutaRaiz,
Ruta_Fichero,
Ruta_Fichero2 : String;

begin

// NombreFichero := ‘Doc1.pdf’;

// RutaRaiz := ‘File:///storage/emulated/0/TabletBigger/Images/Articulos’;
// RutaRaiz := ‘/storage/emulated/0/TabletBigger/Images/Articulos’;
// RutaRaiz := ‘/storage/sdcard0/TabletBigger/Images/Articulos’; // en mi tablet
// Ruta_Fichero := System.IOUtils.TPath.Combine(RutaRaiz, NombreFichero);
// Ruta_Fichero := System.IOUtils.TPath.Combine(System.IOUtils.TPath.GetDownloadsPath, NombreFichero);
// Ruta_Fichero := System.IOUtils.TPath.Combine(System.IOUtils.TPath.GetSharedDownloadsPath, RutaRaiz);

NombreFichero := ‘Introduccion.pdf’;
Ruta_Fichero2 := ‘/storage/emulated/0/TabletBigger/Images/Articulos/Introduccion.pdf’;
Ruta_Fichero := System.IOUtils.TPath.Combine(System.IOUtils.TPath.GetPublicPath, NombreFichero);

showtext.Text := Ruta_Fichero;

open(Ruta_Fichero);

// Ruta_Fichero := StringReplace(StringReplace( Ruta_Fichero, ”, ‘\’, [rfReplaceAll]), ‘”‘, ‘”‘, [rfReplaceAll]) + ‘”‘;
//_system(PAnsiChar(‘Open ‘ + AnsiString(Ruta_Fichero)))

end;

procedure TForm1.Open(Ruta_Fichero : String);
var
Intent: JIntent;
begin

if FileExists(Ruta_Fichero) then
begin
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
Intent.setDataAndType(StrToJURI(Ruta_Fichero), StringToJString(‘application/pdf’));
Intent.setFlags(TJIntent.JavaClass.FLAG_ACTIVITY_CLEAR_TOP);
try
SharedActivity.startActivity(Intent);
Except

end;

end
else
_MessageDlg(‘El fichero no existe’, mssInf);

end;

Comments are closed.