I am using advance Webview to download .zip file in my app from UIDAI website. But when DownloadListener is getting called It returns the correct data, but downloads it's HTML webpage in that .zip file instead of downloading the actual file. whereas when I try downloading the same zip via chrome. It is downloading the correct zip file. Please help me with this problem. why is this happening in webview on this particular website (https://resident.uidai.gov.in/offline-kyc) whereas with the use of same onDownloadRequested function I am able to download files on other websites?
public class MainActivity
extends AppCompatActivity implements AdvancedWebView.Listener {
private static final String QT_TAG = "QT_TAG";
private AdvancedWebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (AdvancedWebView) findViewById(R.id.webview);
mWebView.setListener(this, this);
String url = "https://resident.uidai.gov.in/offline-kyc";
mWebView.loadUrl(url);
}
@Override
public void onDownloadRequested(String url, String suggestedFilename, String mimeType,
long contentLength, String contentDisposition, String userAgent) {
Log.i(QT_TAG, "downloadlistener0: "
+ userAgent +" " + mimeType+" " + contentLength + " "
+ contentDisposition+ " " + url +" "+suggestedFilename);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimeType);
request.setDestinationUri(Uri.fromFile(new File( Environment.DIRECTORY_DOWNLOADS)));
//------------------------COOKIE!!------------------------
String cookies = CookieManager.getInstance().getCookie(url);
request.addRequestHeader("cookie", cookies);
//------------------------COOKIE!!------------------------
request.addRequestHeader("User-Agent", userAgent);
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimeType));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimeType));
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
dm.enqueue(request);
Toast.makeText(getApplicationContext(), "Downloading File0 ", Toast.LENGTH_LONG).show();
}
@SuppressLint("NewApi")
@Override
protected void onResume() {
super.onResume();
mWebView.onResume();
Log.i(QT_TAG, "onResume: ");
// ...
}
@SuppressLint("NewApi")
@Override
protected void onPause() {
mWebView.onPause();
Log.i(QT_TAG, "onPause: ");
// ...
super.onPause();
}
@Override
protected void onDestroy() {
mWebView.onDestroy();
Log.i(QT_TAG, "onDestroy: ");
// ...
super.onDestroy();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (intent.getData() != null){
Log.i(QT_TAG, "onActivityResult: "+ requestCode+" "+ resultCode+" "+intent.getData().toString());
}else{
Log.i(QT_TAG, "onActivityResult: "+ requestCode+" "+ resultCode);
}
mWebView.onActivityResult(requestCode, resultCode, intent);
// ...
}
@Override
public void onBackPressed() {
if (!mWebView.onBackPressed()) {
Log.i(QT_TAG, "onBackPressed: ");
return; }
// ...
super.onBackPressed();
}
@Override
public void onPageStarted(String url, Bitmap favicon) {
Log.i(QT_TAG, "onPageStarted: "+ url);
}
@Override
public void onPageFinished(String url) {
Log.i(QT_TAG, "onPageFinished: "+ url);
}
@Override
public void onPageError(int errorCode, String description, String failingUrl) {
Log.i(QT_TAG, "onPageError "+ errorCode + " "+ description +" "+failingUrl);
}
@Override
public void onExternalPageRequest(String url) {
Log.i(QT_TAG, "onExternalPageRequest: "+ url);
}
}
`
I am using advance Webview to download .zip file in my app from UIDAI website. But when DownloadListener is getting called It returns the correct data, but downloads it's HTML webpage in that .zip file instead of downloading the actual file. whereas when I try downloading the same zip via chrome. It is downloading the correct zip file. Please help me with this problem. why is this happening in webview on this particular website (https://resident.uidai.gov.in/offline-kyc) whereas with the use of same
onDownloadRequestedfunction I am able to download files on other websites?My code: