I'm trying to display a pdf file inside a WebView WITHOUT download it (because some security reasons). I'm using react-native-webview.
In iOS, the PDF file is displaying without any problem. But in Android, when navigate to the screen with the webview, starts a download of the pdf file and, is not displayed on the screen.
There is a way to display directly the pdf file on the screen in the case of Android?
Here is my current code:
<WebView
style={styles.webView}
startInLoadingState
renderLoading={() => <LoadingIndicator />}
source={{ uri: document.url }}
/>
Thanks a lot in advance.
Related
I'm new to React Native, coding an app for web and android. On web, my images display fine. On Android, some of them don't show. jpgs etc display fine but the images I need are .avif and they do not. Just a blank space shows in place of the image.
const imageSrc = "https://grocer-img.sgp1.cdn.digitaloceanspaces.com/products/4781330397012883.avif"
<Image source={{
uri: imageSrc,
}}
style={styles.productImage}
resizeMethod="resize"
></Image>
productImage: {
width: "90%",
aspectRatio: 1,
}
Does anyone know how I can get my images to work on both web and android?
I've tried using a locally stored .avif to test and that doesn't work either.
If you are testing with Android OS less than version 12, the AVIF image format is not supported - https://developer.android.com/about/versions/12/features#avif
Tried with multiple prefix urls: (FINAL_URL = PREFIX_URL+DOCUMENT_URL)
Prefix urls:
https://drive.google.com/viewerng/viewer?embedded=true&url=
https://docs.google.com/viewer?url=
I used react-native-webview for this
<WebView
source={{
uri: `${PREFIX_URL}${attachmentUrl}`
}}
javaScriptEnabled={true}
cacheEnabled={false}
startInLoadingState={true}
/>
Did you share the document with a setting allowing anyone with a link to view it? It might be that you simply have to be logged into google drive to view it.
You can test it by opening the URL in an incognito tab
I am quite new to React-native. The href tag in HTML opens the website within the app. I wish to have it open the link in the default browser of the mobile phone/device. Oh and I use snack.expo.
In APP a website is being loaded. Within my website I use <a href> 'http://maps.google.com/?q=...' I wish to have the default browser of a mobile phone to open this link in its default browser, same goes for other href links.
Of course only links with target="_blank" should be opened in the default browser.
It would be even more awesome if app's can be opened.
I have searched google a lot, but without success.
Anyone who knows how to do this? Or is it simply not available, yet?
Within my HTML code I've tried this:
{address}
Part of react native code:
return (
<WebView
source={{ uri: '{website}' }}
/>
);
Best regards
It is definitely possible in react native. You can do it as follows:
import {Linking} from "react-native"
<WebView
source={{uri:"https://mashupguide.net/1.0/html/ch02s05.xhtml"}}
onShouldStartLoadWithRequest={request => {
let url = request.url;
if (url.includes("http://maps.google.com/")) {
Linking.openURL(url);
return false
} else {
return true
}
}}
/>
This will prevent the WebView from browsing to the next page and instead open the phone's default browser.
reference: https://github.com/react-native-community/react-native-webview/blob/master/docs/Reference.md#onshouldstartloadwithrequest
working example: https://snack.expo.io/#ammarahmed/sadistic-almond
This is my code below:
<View style={{height:250}}>
<WebView
style={ styles.WebViewContainer }
javaScriptEnabled={true}
domStorageEnabled={true}
source={{uri: 'https://www.youtube.com/embed/BE1WzycXP10' }}
/>
</View>
When the external player opens and I press the BACK button - application closes without errors. I think that the new intent creates in the same activity.So my question: Is there any way to open video links with external player (like share works but user need to select from video players installed on the system to open shared link with the selected one)
I have an Android application that displays .mht file .In order to make that happen , I tried:
webview.loadDataWithBaseURL("", s, "multipart/related", "UTF-8", "");
But that displays unwanted content on the screen like this . Does anyone have any idea of why the WebView does not show .mht file?
The WebView do not support .mht file type.
Note: The Opera Mini can open the .mht files.