0
I wish I could make a button that when clicked, download a pdf with the url of this to sdcard, but I’m not getting at all...
0
I wish I could make a button that when clicked, download a pdf with the url of this to sdcard, but I’m not getting at all...
3
You can use the class DownloadManager
from Android itself. It will already do all the work for you (including notifications with progress and success/failure):
String url = "http://suaurl.com.br/";
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setDescription("Alguma descrição");
request.setTitle("Algum titulo");
//A notificação de conslusão só esta disponível a partir da API 11
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
//Salvando o arquivo no diretório de Downloads
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "MeuPdf.pdf");
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
The result will be like this:
And when complete:
You can view the file in the folder Downloads
:
Browser other questions tagged java android url pdf
You are not signed in. Login or sign up in order to post.
AP was supposed to accept your answer, I needed to do that, and I used your answer as a basis :)
– Wellington Avelino