Próbuję pobrać plik przy użyciu webView z hostów plików (takich jak zippyshare.com). Problem polega na tym, że nie mogę używać intencji do otwierania przeglądarki lub przekierowywać go za pomocą funkcji DownloadManager, ponieważ jest to sesja/plik cookie, a uruchomienie tych metod przekierowuje plik zip do oryginalnego pliku html w celu ponownego pobrania.Jak mogę użyć Androida do pobrania pliku sesji/pliku cookie przy użyciu webView?
Próbowałem:
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);
oraz:
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);
próbować zachować cookie, a jednocześnie widzę nagłówki wysyłane są w porządku, to nadal przekierowuje do łącza html , co prowadzi mnie do przekonania, że jest to sesja.
Czy istnieje sposób pobrania pliku w ten sposób?
Dzięki tobik, będę wyglądał wieczorem, mam nadzieję, że to zadziała :) – trueicecold