ファイル ホスト (zippyshare.com など) から webView を使用してファイルをダウンロードしようとしています。問題は、インテントを使用してブラウザーを開いたり、DownloadManager を介して再ルーティングしたりできないことです。これは、セッション/Cookie ベースであるためです。これらのメソッドを起動すると、zip ファイルが元の html ファイルにリダイレクトされて再ダウンロードされます。
私はもう試した:
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);
と:
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);
Cookie を保存しようとすると、ヘッダーが正常に送信されていることがわかりますが、それでも html リンクにリダイレクトされるため、セッション ベースであると思われます。
その方法でファイルをダウンロードする方法はありますか?