Is it possible to open an external app when touching a button from my react native app? Specifically, i want to open Whatsapp when I touch a button. How can I do this?
Thanks!
Is it possible to open an external app when touching a button from my react native app? Specifically, i want to open Whatsapp when I touch a button. How can I do this?
Thanks!
You have to use React Native Linking API:
Linking.openURL('whatsapp://app')
Also, have a look at How can I integrate WhatsApp into my app
Previously below was used,
Linking.openURL('whatsapp://app');
But later the URL is changed as follows, we can also add phone and text query params shown below,
Linking.openURL(`whatsapp://send?phone=${whatsappNo}&text=${whatsappMsg}`);
You can try to use parameters from the API of the application. For example in my case I had to open maps on IOS and start a navigation from Point A to B. So I checked the documentation from HERE, and used the navigation link: "http://maps.apple.com/?saddr=Cupertino&daddr=San+Francisco" to create the query to open the app:
<TouchableOpacity onPress={() => Linking.openURL('maps://app?saddr=Cupertino&San+Francisco')}>
<Text>Navigate</Text>
</TouchableOpacity>
You can use coordinates too, as lat and long :
maps://app?saddr=Cupertino&S100.123+101.222
i wanted to open whatsapp on a click of simple button in my react-native application, which i am developing for android.
I have searched a lot about this but did not got any perfect solution. Although i found one third party library "npm i -S react-native-app-link".
The description in this library is exactly what i wanted to do. But not able to figure it out. If any of you can help it out it will be a great favor for me.
React Native don't have support to 'whatsapp://' scheme.
Only for this Schemes:
A altenative is use the Whatsapp Universal links with React Native Linking:
https://wa.me/<number>
https://reactnative.dev/docs/linking.html#open-links-and-deep-links-universal-links
You can use this package https://github.com/khorark/rn-openapp for opening any other app on android phone.
Just that you need to know the app id of the required app. You may get it from play store url of the app (it is present right after ?id ) Example.
Use this package https://github.com/danilrafiqi/react-native-open-application with this https://github.com/FiberJW/react-native-app-link
so if the application is already installed, open it immediately, but if it is not installed it will go directly to the google play store
const onPresss = () => {
OpenApplication.openApplication('com.dev47apps.droidcam')
.then(() => {})
.catch(err => {
AppLink.maybeOpenURL('droidcam://', {
appName: 'DroidCam',
appStoreId: '',
appStoreLocale: '',
playStoreId: 'com.dev47apps.droidcam',
})
.then(() => {})
.catch(err => {});
});
};
resolve this error as follows:
export async function openAppSpecific(urlScheme = 'https://wa.me/', storeURL = 'https://play.google.com/store/apps/details?id=com.whatsapp') {
const url = urlScheme;
try {
const supported = await Linking.canOpenURL(url);
if (supported) {
await Linking.openURL(url);
} else {
const storeUrl = storeURL;
await Linking.openURL(storeUrl);
}
} catch (error) {
toast.failedCustom("Erro ao abrir o aplicativo :(");
}
}
it is always necessary to pass a scheme url, it is as if it were a single link of the application that you want to open. As an example I used whatsapp.