1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
//authenticate smb share
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("DOMAINE", "LOGIN", "PASSWORD");
//chemin du pdf
SmbFile pdf = new SmbFile("file://<serveur>/<chemin>/<fichier>.pdf", auth);
String smbFileName = pdf.getName();
//stream fichier entrant
InputStream inputStream = pdf.getInputStream();
//destination folder
File localFilePath = new File(Environment.getExternalStorageDirectory().getPath()+ "/" + smbFileName);
//stream output
OutputStream out = new FileOutputStream(localFilePath);
//copy...
byte buf[] = new byte[1024];
int len;
while ((len = inputStream.read(buf)) > 0)
{
out.write(buf, 0, len);
}
//closing streams
out.flush();
out.close();
inputStream.close();
//create intent to start pdf reader
Intent target = new Intent(Intent.ACTION_VIEW);
target.setDataAndType(Uri.fromFile(localFilePath),"application/pdf");
target.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
Intent intent = Intent.createChooser(target, "Open File");
startActivity(intent); |