在android應用程序內下載文件。我正在嘗試從URL 下載文件。當我從普通瀏覽器打開URL時,它將我重定向到一個登錄頁面,一旦我登錄,下載開始 。我需要在我的應用程序 中具有相同的功能。我需要通過webview登錄。一旦我登錄,下載應該被觸發。無法使用webview
當我使用下面的邏輯,即使我在web視圖登錄,瀏覽器重定向到登錄頁面。請幫忙。
private void loadPage(final String iUrl) {
// TODO Auto-generated method stub
WebView webView = (WebView) findViewById(R.id.webView1);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setBuiltInZoomControls(true);
int default_zoom_level=100;
webView.setInitialScale(default_zoom_level);
final Activity activity = this;
webView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
activity.setTitle("I-Aurora: Loading...");
}
});
webView.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), description, Toast.LENGTH_SHORT).show();
}
public void onPageFinished (WebView view, String url) {
activity.setTitle("I-Aurora: Login");
}
});
webView.setDownloadListener(new DownloadListener() {
public void onDownloadStart(String url, String userAgent,String contentDisposition,String mimetype,long contentLength) {
Intent int3 = new Intent(Intent.ACTION_VIEW);
int3.setClassName("com.android.chrome", "com.google.android.apps.chrome.Main");
int3.setData(Uri.parse(url));
startActivity(int3);
}
});
webView.loadUrl(iUrl);
Button button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Button Click" , Toast.LENGTH_SHORT).show();
}
});
return;
}
您可以在請求頭添加cookie。 http://stackoverflow.com/questions/22935214/file-download-not-working-in-android-using-cordova-2-9-0/24646292#24646292 – h3n