. I am trying to download a file from URL . When I open the URL from normal browser, it redirects me to a login page and once I login, download starts . I need to have the same functionality in my application . I need to login via a webview. Once I login, download should be triggered.
When I use the below logic, even after I login in webview, browser redirects to login page. Please help.
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;
}