Android DownloadManager "Impossible to open file"
android, download, download-manager
Solution
Okay I found the problem !
I had to specify the "MIME content type" of the file using setMimeType().
public DownloadManager.Request setMimeType (String mimeType);
Problem
I'm using DownloadManager to download a file from a webService. The download end successfuly, but when I try to open the new file in the "download" folder I've got this error "Impossible to open file" (and I know I can open this type of file). Also, when I plug my phone to my computer and when I open the download file with it, the file open successfuly and is not corrupted. I don't have other error, so I'm really lost ! Here my code: ``` /*Data*/ int filePosition = position - _subFolderNameList.length; String url = _folder.getFiles().get(filePosition).getUrl(); String FileName = _folder.getFiles().get(filePosition).getName(); String Description = _folder.getFiles().get(filePosition).getUrl(); /*Prepare request*/ DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setDescription(Description); request.setTitle(FileName); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, FileName); DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); manager.enqueue(request); // Send request ``` Edit: Permission in the Manifest: ``` <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> ```