Prezado Matheus,
Infelizmente não consegui utilizar a biblioteca.
Meu problema é que o arquivo baixa na pasta download, mas não consigo lê-lo.
Rotina de download, funciona e baixa o arquivo na pasta download
DownloadManager downloadManager =
(DownloadManager) getSystemService(DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); long downloadId = downloadManager.enqueue(request);
DownloadApplication app = (DownloadApplication) getApplication();
app.downloadsAtivos.add(downloadId);
// Classe DownloadReceiver
public class DownloadReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
long downloadId = intent.getExtras().getLong(DownloadManager.EXTRA_DOWNLOAD_ID);
DownloadApplication app =
(DownloadApplication) context.getApplicationContext();
if (app.downloadsAtivos.indexOf(downloadId) != -1) {
DownloadManager.Query query = new DownloadManager.Query();
query.setFilterById(downloadId);
DownloadManager downloadManager =
(DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
Cursor cursor = downloadManager.query(query);
if (cursor.moveToFirst()) {
String uri = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI ));
String mime = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_MEDIA_TYPE));
Uri ArquivoPDF = Uri.parse(uri) ;
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +"/"+ "Comunicado-Tecnico-79.pdf");
File path = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) +"/"+ "Comunicado-Tecnico-79.pdf");
File path2 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
Intent abreArquivoIntent = new Intent(Intent.ACTION_VIEW);
abreArquivoIntent.setDataAndType(Uri.fromFile(path), "application/pdf");
abreArquivoIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent intent2 = Intent.createChooser(abreArquivoIntent, "Abrir arquivo");
context.startActivity(intent2);
try {
if (file.exists()) {
Toast.makeText(context,
"Arquivo existe", Toast.LENGTH_SHORT).show();
} else{
Toast.makeText(context,
"Arquivo não existe", Toast.LENGTH_SHORT).show();
}
} catch (ActivityNotFoundException e) {
}
PackageManager packageManager = context.getPackageManager();
if (packageManager.resolveActivity(abreArquivoIntent, 0) != null) {
PendingIntent acaoPendente =
PendingIntent.getActivity(context, 0,
abreArquivoIntent, PendingIntent.FLAG_CANCEL_CURRENT);
Notification notificacao = new NotificationCompat.Builder(context)
.setContentTitle("Download terminado")
.setContentText(uri)
.setSmallIcon(android.R.drawable.ic_menu_slideshow)
.setAutoCancel(true)
.setContentIntent(acaoPendente)
.build();
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(123, notificacao);
Toast.makeText(context,
"Download concluído", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context,
"Não tem aplicativo para abrir o download", Toast.LENGTH_SHORT).show();
}
}
Toast.makeText(context,
"Não tem aplicativo para abrir o download", Toast.LENGTH_SHORT).show();
}
}
cursor.close();
app.downloadsAtivos.remove(downloadId);
}
}
cursor.close();
app.downloadsAtivos.remove(downloadId);
}
}