He intentado descargar el archivo a la carpeta cache para abrir el archivo desde alli pero tampoco consigo abrirlo, mi código es este.
En una consulta obtengo la url y la monto correctamente para samba.
enlace = (rs.getString("IDENTHIJO"));
enlace= enlace.replace("\\", "/");
enlace = enlace.replaceAll("FICHEROS", "192.168.10.12");
compruebo que el archivo samba existe y si existe, lo copio a la carpeta cache.
Si existe en la carpeta cache lanzo el metodo mostrarPDF.
try {
String user = "xxxxx";
String pass = "xxxxx";
String url = "smb:" + enlace;
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(
"xxxxxxx", user, pass);
SmbFile sfile = new SmbFile(url, auth);
if (sfile.exists()) {
File destination = new File(getCacheDir(), "plano.pdf");
destination.createNewFile();
Uri path = Uri.parse(destination.toString());
InputStream in = sfile.getInputStream();
OutputStream out = new FileOutputStream(destination);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
if (destination.exists()) {
mostrarPDF(path, ComprobarAlmacen.this);
destination.delete();
} else {
Toast.makeText(ComprobarAlmacen.this, "NO EXISTE EL ARCHIVO", Toast.LENGTH_SHORT).show();
}
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(ComprobarAlmacen.this, "No he llegado", Toast.LENGTH_SHORT).show();
}
}
Y el metodo para abrir el PDF
public void mostrarPDF(Uri nombPdf, Context context) {
Toast.makeText(context, "Visualizando documento", Toast.LENGTH_LONG).show();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(nombPdf, "application/pdf");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(context, "No existe una aplicación para abrir el PDF", Toast.LENGTH_SHORT).show();
}
}
El log me muestra lo siguiente
2020-09-16 17:17:44.943 2635-2700/com.example.errece D/EGL_emulation: eglMakeCurrent: 0xdd505480: ver 3 0 (tinfo 0xdd503770)
2020-09-16 17:17:52.603 2635-2635/com.example.errece I/Choreographer: Skipped 455 frames! The application may be doing too much work on its main thread.
2020-09-16 17:17:52.610 2635-2700/com.example.errece I/OpenGLRenderer: Davey! duration=7600ms; Flags=0, IntendedVsync=86432318701565, Vsync=86439902034595, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=86439912154900, AnimationStart=86439912207700, PerformTraversalsStart=86439912382700, DrawStart=86439912513600, SyncQueued=86439913529800, SyncStart=86439913642800, IssueDrawCommandsStart=86439913721300, SwapBuffers=86439914151700, FrameCompleted=86439919075000, DequeueBufferDuration=68000, QueueBufferDuration=2491000,
2020-09-16 17:17:52.710 2635-2700/com.example.errece D/EGL_emulation: eglMakeCurrent: 0xdd505480: ver 3 0 (tinfo 0xdd503770)
2020-09-16 17:17:52.733 2635-2700/com.example.errece D/EGL_emulation: eglMakeCurrent: 0xdd505480: ver 3 0 (tinfo 0xdd503770)
2020-09-16 17:17:52.928 2635-2700/com.example.errece D/EGL_emulation: eglMakeCurrent: 0xdd505480: ver 3 0 (tinfo 0xdd503770)
2020-09-16 17:17:52.932 2635-2700/com.example.errece D/EGL_emulation: eglMakeCurrent: 0xdd505480: ver 3 0 (tinfo 0xdd503770)
No se como tengo que hacerlo!!!!
muchas gracias!!!!