Download Unsuccessful when using DownloadManager.Request to download the file from url
<p>I'm trying to download the file from the server using DownloadManager but It fail's to download and say's Download unsuccessful, I have read that there is a issue with Download Manager in the below link
<a href="https://stackoverflow.com/questions/17374621/android-chrome-browser-unnecessarily-renames-names-types-of-downloaded-files">android-chrome-browser-unnecessarily-renames-names-types-of-downloaded-files</a> so I tried to download the file by adding the RequestHeader to the DownloadManagerRequest using below method but nothing happened. please find the below code part of my Downloader class anyone please suggest me the right way to download the file from url using DownloadManager.</p>
<p>url:</p>
<blockquote>
<p>http://<em><strong>-storage.</strong></em>.net/95-****/95-3194.pdf?AWSAccessKeyId=T9YG9HWQC1LHE5G5VF38&amp;Expires=1483443248&amp;Signature=Z%2BkWzfEI2VawbCx%2F2Yto1kPcJKA%3D</p>
</blockquote>
<p>Thanks</p>
<pre><code>public void download(Uri uri) {
    if (!isDownloading()) {
        String fileName=getName(uri);
        DownloadManager.Request request = new DownloadManager.Request(uri);
        request.setTitle(fileName);
        request.setNotificationVisibility(1);
        request.allowScanningByMediaScanner();
        request.addRequestHeader(&quot;Content-Type&quot;, &quot;application/octet-stream&quot;);
        request.addRequestHeader(&quot;Content-Disposition&quot;, &quot;attachment; filename=\&quot;&quot;+fileName.split(&quot;\\.&quot;)[0]+&quot;.&quot;+fileName.split(&quot;\\.&quot;)[1].toUpperCase()+&quot;\&quot;&quot;);
        String cookieContent = getCookieFromAppCookieManager(uri.getHost());
        request.addRequestHeader(&quot;Cookie&quot;, cookieContent);
        downloadId = downloadManager.enqueue(request);
        register();
    }
}
</code></pre>
<p>and below block returns the File name</p>
<pre><code>private String getName(Uri uri) {
    String name=uri.toString().split(&quot;jabord/&quot;)[1].split(&quot;\\?&quot;)[0];
    return name;
}
</code></pre>
<p>returns the appcookie manager</p>
<pre><code>public String getCookieFromAppCookieManager(String url) {
    android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance();
    if (cookieManager == null) {
        return null;
    }
    String rawCookieHeader = null;

    // Extract Set-Cookie header value from Android app CookieManager for this URL
    rawCookieHeader = cookieManager.getCookie(url);
    if (rawCookieHeader == null) {
        return null;
    }

    return rawCookieHeader;
};
</code></pre>