Ver Mensaje Individual
  #1  
Antiguo 30-01-2019
Avatar de turbopascual5.0
turbopascual5.0 turbopascual5.0 is offline
Miembro
 
Registrado: feb 2011
Posts: 54
Reputación: 14
turbopascual5.0 Va por buen camino
Abrir Pdf En Api 26

Hola.

Al compilar para api 26 en Rio, al abrir un pdf obtengo este error que antes no aparecía

android.os.FileUriExposedException: file:///Storage/emulated/0/Download/AppDataDetails/trabajo.pdf exposed beyond app through Intent.getData()

El código es

Código Delphi [-]
     URI := TJnet_Uri.JavaClass.parse(StringToJString('file:///' + ficheropuente));
      intent := TJIntent.Create;
      intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
      intent.setDataAndType(URI,StringToJString('application/pdf'));
      Tandroidhelper.Activity.startActivity(intent);[/font][/color]

Buscando he encontrado una solución


You'll need this unit:
https://github.com/DelphiWorlds/Kast...leProvider.pas
for this code:

uses Androidapi.JNI.JavaTypes, Androidapi.JNI.Net, Androidapi.JNI.GraphicsContentViewText, Androidapi.Helpers;procedure OpenPDF(const AFileName: string);var LIntent: JIntent; LAuthority: JString; LUri: Jnet_Uri;begin LAuthority := StringToJString(JStringToString(TAndroidHelper.Context.getApplicationContext.getPackageName)+'.fileprovider'); LUri := TJFileProvider.JavaClass.getUriForFile(TAndroidHelper.Context, LAuthority, TJFile.JavaClass.init(StringToJString(AFileName))); LIntent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_VIEW); LIntent.setDataAndType(LUri, StringToJString('application/pdf')); LIntent.setFlags(TJIntent.JavaClass.FLAG_GRANT_READ_URI_PERMISSION); TAndroidHelper.Activity.startActivity(LIntent);end;




Pero ahora me da error

java.lang.illegalArgumentsException Failed to find configured root that contains /file: /data/user/0/com.embarcadero.PRODUCCION/files/trabajo.pdf

El pdf lo leo de una base de datos y lo grabo así:

Código Delphi [-]
ficheropuente:=TPath.Combine(TPath.GetPublicPath, 'trabajo.pdf');
TBlobField(uniquery2documento).SaveToFile(ficheropuente);

Alguna idea?, gracias de antemano





Última edición por Neftali [Germán.Estévez] fecha: 31-01-2019 a las 08:23:00. Razón: Añadir TAG's al código
Responder Con Cita