Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] How to prevent default Download Manager #3401

Open
ivankdev opened this issue Apr 15, 2024 · 1 comment
Open

[Android] How to prevent default Download Manager #3401

ivankdev opened this issue Apr 15, 2024 · 1 comment

Comments

@ivankdev
Copy link

ivankdev commented Apr 15, 2024

Integrating webview in my RN app. I use Publitas API as url resource and need to handle onFileDownload event on android. This is minimal code snippet for repro.

"react-native-webview": "^13.8.4",
import { Alert } from 'react-native'
import WebView from 'react-native-webview'

export const App = () => {
  return (
    <WebView
      source={{ uri: 'https://view.publitas.com/delhaize-belgium/2023-w42-fr' }} // just example of url
      onFileDownload={(url) => {/* downloading */}} 
    />
  )
}

So according to official documentation, onFileDownload works of course only on ios, so I can easily handle it on JS side.
On android by default clicking on "download" from on web view always handled by default Download Manager, so user ALWAYS redirected to external browser, but user needs to stay inside app instead.

I've tried to watch through web view native code, but need some advice how to override that behaviour even on native side, default methods like

public void downloadFile(String downloadingMessage)

related to download logic even not being called


Question: Any clues how to stop default android behaviour with Download Manager and handle url manually?

@ivankdev
Copy link
Author

this mentioned solution not working for me #2405 (comment) since onShouldStartLoadWithRequest not being called on download button press

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant