Am new to React-native. We are trying to implement a react-native App in which a button will be provided so that whenever a user clicks on the button he will be directed to play store if the app is not installed. If the App is already installed on the button click he should be able to open the app which is currently not happening.
AndroidManifest.xml
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT">
</category>
<category android:name="android.intent.category.BROWSABLE">
</category>
<data android:scheme="whatsapp"></data>
</intent-filter>
Above is the code which we modified with in the AndroidManifest.xml file.
App.js We have a method called handle() which will handle the events
handle(){
let appName = 'whatsapp';
let url = 'https://play.google.com/store/apps/details?id=com.whatsapp';
Linking.openURL(url).catch(err => {
if (err.code === 'EUNSPECIFIED') {
if (Platform.OS === 'android') {
Linking.openURL(
url
);
}
} else {
throw new Error(`Could not open ${appname}. ${err.toString()}`);
}
});}
The above code is working fine for opening an app in Playstore. But when the app is installed already in the device it on the button click it should directly open the App using Custom url.
When we are using canOpenURL() with Custom Url schema it does nothing. And when i use Custom Url schema with openURL() it is giving me a warning saying no action is provided or defined in the android.intent.action.VIEW but it is provided.
const url = 'whatsapp://';
Linking.canOpenURL(url).then(supported => {
if (!supported) {
console.log('Can\'t handle url: ' + url);
}else {
return Linking.openURL(url);
}
}).catch(err => console.error('An error occurred', err));
Please help us. Thanks in Advace!!