react-native-webview / react-native-webview

React Native Cross-Platform WebView
https://github.com/react-native-community/discussions-and-proposals/pull/3
MIT License
6.31k stars 2.96k forks source link

[Android] How to prevent default Download Manager #3401

Closed ivankdev closed 4 days ago

ivankdev commented 2 months ago

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 commented 2 months ago

this mentioned solution not working for me https://github.com/react-native-webview/react-native-webview/issues/2405#issuecomment-1064795293 since onShouldStartLoadWithRequest not being called on download button press

github-actions[bot] commented 1 week ago

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically