android - DownloadManager with cookie authentication -


i'm trying zip file using downloadmanager parsing cookie jsessionid server. i'm getting jsessionid doing process login using httpclient lib , setting variable jsessionid later use in downloadmanager request.

my download request:

    downloadmanager.request request = new downloadmanager.request(uri.parse(htmlurldownload));      request.addrequestheader("cookie", "jsessionid=" + jsessionid);     request.addrequestheader(constants.user_agent, constants.target_request_header);      request.setdescription("baixando " + metadado.gettype());     request.settitle("download");     request.allowscanningbymediascanner();     request.setnotificationvisibility(downloadmanager.request.visibility_visible_notify_completed);      string namefile = offlineuuid + ".zip";      filename = namefile;      filepath = environment.getexternalstoragedirectory() + file.separator + environment.directory_downloads             + file.separator + filename;      request.setdestinationinexternalpublicdir(environment.directory_downloads, namefile);      final downloadmanager manager = (downloadmanager) getsystemservice(context.download_service);      final long downloadid = manager.enqueue(request); 

the problem download never starts , column_reason returns code error_unhandled_http_code

but if try download same file using dropbox link without authentication or using httpclient, it's works perfectly, doing wrong?

how can better msg error?

nothing wrong in code, seems server responding http redirect staus code, causing downloadmanager fail process download.

from android docs :-

public static final int error_unhandled_http_code

added in api level 9 value of column_reason when http code received download manager can't handle.

see below code snippet:-

from android framework source code downloadmanger.java

case downloads.impl.status_unhandled_http_code:                 case downloads.impl.status_unhandled_redirect:                     return error_unhandled_http_code; 

so need check server logs issue, or pass direct file url download manager doesn't cause redirect.

also please note need below 2 permissions in androidmanifest.xml download work expected

<uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.write_external_storage"/> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -