Sto provando a scaricare un file usando webView dagli host di file (come zippyshare.com). Il problema è che non posso usare intenti per aprire un browser, o reindirarlo tramite DownloadManager, poiché è basato su sessione/cookie, e l'avvio di tali metodi reindirizza il file zip nel file html originale a re-downlad.Come posso utilizzare Android per scaricare un file basato su sessione/cookie usando webView?
ho provato:
Uri source = Uri.parse(url);
DownloadManager.Request request = new DownloadManager.Request(source);
String cookie = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("Set-Cookie", cookie);
request.addRequestHeader("User-Agent", view.getSettings().getUserAgentString());
request.addRequestHeader("Accept", "text/html, application/xhtml+xml, *" + "/" + "*");
request.addRequestHeader("Accept-Language", "en-US,en;q=0.7,he;q=0.3");
request.addRequestHeader("Referer", url);
// Use the same file name for the destination
final File destinationDir = new File (Environment.getExternalStorageDirectory(), cordova.getActivity().getPackageName());
if (!destinationDir.exists()) {
destinationDir.mkdir(); // Don't forget to make the directory if it's not there
}
File destinationFile = new File (destinationDir, source.getLastPathSegment());
Log.e("FILEPOSITION", Uri.fromFile(destinationFile).toString());
request.setDestinationUri(Uri.fromFile(destinationFile));
// Add it to the manager
manager.enqueue(request);
e:
Bundle bundle = new Bundle();
String cookie = CookieManager.getInstance().getCookie(url);
bundle.putString("cookie", cookie);
bundle.putString("User-Agent", view.getSettings().getUserAgentString());
Intent intent = new Intent(Intent.ACTION_VIEW ,Uri.parse(url));
intent.putExtra(Browser.EXTRA_HEADERS, bundle);
cordova.getActivity().startActivity(intent);
per cercare di conservare il cookie, e mentre vedo le intestazioni vengono inviati bene, reindirizza ancora al link html , che mi porta a credere che sia basato sulla sessione.
Esiste un modo per scaricare un file in questo modo?
Grazie a tobik, darò un'occhiata alla sera, spero che funzioni :) – trueicecold