ファイルホスト(zippyshare.comなど)からwebViewを使用してファイルをダウンロードしようとしています。 問題は、セッション/ Cookieベースのため、ブラウザを開く、またはDownloadManager経由で再ルーティングすることができません。これらのメソッドを起動すると、zipファイルが元のhtmlファイルにリダイレクトされて再ダウンします。webViewを使用してAndroidを使用してセッション/ Cookieベースのファイルをダウンロードするにはどうすればよいですか?
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);
はクッキーを保存しようとする、と私はヘッダがうまく送信された参照しながら、それはまだHTMLリンクにリダイレクトそれは私がそれがセッションに基づいていると信じさせる。
このようにファイルをダウンロードする方法はありますか?
tobikさん、ありがとうございました。 – trueicecold