Webview not working on Android

Hi, I am trying to use a WebView (react-native-webview) to display the content of a file received from my server. The file could be an Excel, a PDF, a Word, an image, etc.

It works fine with iOS. But with Android, the device is telling me that a download was done but the WebView stays empty. If I go see the downloaded file outside my app, I will not be able to open it. I will have an error saying ERR_FILE_NOT_FOUND.

Do you know what is missing? Is there something I must add in the app config to enable this on Android ?

react: 17.0.1
expo: 43.0.2
react-native-webview: 11.13.0

Here is my code.

> const DocumentScreen = ({ route, navigation }) => {
>   const { id, name } = route.params;
>   const [url, setUrl] = useState(null);
>   const [accessToken, setAccessToken] = useState(null);
> 
>   useEffect(async () => {
>     const _url = global.BASE_URL + "/Document/Download/" + id;
>     setUrl(_url);
> 
>     const _accessToken = await SecureStore.getItemAsync("accessToken");
>     setAccessToken(_accessToken);
>   }, []);
> 
>   return (
>     <>
>       {url != null && accessToken != null ?
>         <WebView style={styles.container}
>           source={{
>             uri: url,
>             headers: { Authorization: `Bearer ${accessToken}` },
>           }}
>       /> : null}
>     </>
>   );

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.