I successfully downloaded a pdf file using DownloadManager API in android.
Manifest permissions are set correctly. File downloaded correctly.
But when it is tried to open it says "can't open file".
Please help to open the downloaded file. I guess I was failing to set the proper name and extension for the file. How to set it?
private void DownloadBook(String url, String title){
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
//request.setDescription("Some descrition");
String tempTitle = title.replace(" ","_");
request.setTitle(tempTitle);
// in order for this if to run, you must use the android 3.2 to compile your app
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, tempTitle+".pdf");
// get download service and enqueue file
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
request.setMimeType(".pdf");
request.allowScanningByMediaScanner();
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_MOBILE | DownloadManager.Request.NETWORK_WIFI);
manager.enqueue(request);
}