delight-im / Android-AdvancedWebView

Enhanced WebView component for Android that works as intended out of the box
MIT License
2.39k stars 574 forks source link

unable to download file leading to crush #239

Closed katlegoN closed 5 years ago

katlegoN commented 5 years ago

Good day, when i click the download button inside the webview nothing happens and this will eventually lead to the app crushing when i click multiple times repeatedly, the download button works fine in the all browsers by the way. I have followed all the necessary procedures from the read me on the implementation of the webview. I have tested it on a real device android 8.0 (API 26) as well as android 7.0 (API 24). Please help

ocram commented 5 years ago

Did you get any exceptions? Can you share a stack trace?

Does this have the same reason as https://github.com/delight-im/Android-AdvancedWebView/issues/235?

katlegoN commented 5 years ago

There are no exception or errors displayed at all it just does nothing, when the download button is clicked nothing happens, If i click multiple times repeatedly it crushes the site a "Resource limit is reached" error is displayed on the site as result. I thought i should mention that the site has back-end development with PHP for authentication (user log in/ registration) and file upload management as well, i don't know if that makes a difference on to handle download requests but if so can you please help.

here is the code handling the download as explained in the read.me

`@Override public void onDownloadRequested(String url, String suggestedFilename, String mimeType, long contentLength, String contentDisposition, String userAgent) {

    if (AdvancedWebView.handleDownload(this, url, suggestedFilename)) {

        // The download is successful 
        Toast.makeText(MainActivity.this, "Download Successful!", Toast.LENGTH_LONG).show();

    } else {

    // Could not download file
        Toast.makeText(MainActivity.this, "Download Failed!", Toast.LENGTH_LONG).show();

    }
}`

Well compared to #235 i just noticed that the app is not the one crushing but repeatedly clicking the download button on the webview crushes causes the website to exceed the resource limit, i think it has to do with the site itself and its back-end (server-side) not the webview.

But the i do experience the same problem as #235 with regards to the WRITE_EXTERNAL_STORAGE permission, i have to go to the android setting to manually allow the permission for the app to use the storage on the device, it doesn't do it automatically nor does a pop up appear asking me for permission

ocram commented 5 years ago

Well, the core issue here is certainly something different than that in the other thread.

You should first add logging to check whether onDownloadRequested is called at all.

Please also check if you implemented all callbacks as described in the README, especially onActivityResult.

katlegoN commented 5 years ago

well the onActivityyResult is implemented as follows, i dont know if i should add anything else:

@Override public void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); mWebView.onActivityResult(requestCode, resultCode, intent); }

I implemented a log message on the OnDownloadRequested and turns out it is not called at all. Any suggestion or solution to this?

By the way thank you for your time and effort

ocram commented 5 years ago

The implementation of that callback looks good. Are you sure you have that in every Activity and Fragment that contains an AdvancedWebView instance?

The log message not appearing indicates that this might not be the case.

katlegoN commented 5 years ago

The attached is the full code of the project, i only have one Activity (mainActivity) on the project fullcode.txt

Please review it and notify me of any errors or mistakes

ocram commented 5 years ago

The code looks good. Can you try with another website, i.e. any popular website that has a download link somewhere? It might be your HTML or HTTP headers.

katlegoN commented 5 years ago

Ok i have tried it with other site and it works, so its the problem with the website, i will get it fixed

Thank you for your time

ocram commented 5 years ago

No problem!