Please provide the following:
- SDK Version: 41.0.0
- Platforms(Android/iOS/web/all): Android/iOS
- Add the appropriate “Tag” based on what Expo library you have a question on.
I am currently trying to implement push notifications. Once the user taps a notification, the app should open on the notifications tab.
In order to do so, I added a listener, which will get an url and use Linking in order to navigate the user to the determined URL.
responseListener.current = Notifications.addNotificationResponseReceivedListener(
(response) => {
const url = response.notification.request.content.data.route;
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));
}
);
}, []);
The URL is sent via the expo Push notifications tool in the Data (JSON) field:
{“route”: “exp://exp://130.64.155.227:19000/–/notifications”}
Which is then used to create an url in a separate file:
const prefix = Linking.createURL('/');
// NOTE: Config object can be used to map all React Navigation routes in the app
// Only notifications route is specified bc it's the only deeplinking case
const config = {
screens: {
tabs: {
screens: {
TAB_NOTIFICATION: 'notifications',
},
},
},
};
const linking = {
config,
prefixes: [prefix],
};
export default linking;
This code works perfectly on iOS devices, however it does not work on android. This was tested for android versions 9, 10 and 11.
When a user taps on a notification, two different behaviors may happen:
- It runs the Linking.openURL(url), however, nothing happens,
- It runs the Linking.openURL(url) and a “Network response timed out” error happens.
I believe there is something wrong with the URL we are passing in the Data(JSON) field, however I do not understand why it works for iOS and not Android.
Note – The intentFilters for android were set like this:
"android": {
"versionCode": 400000019,
"intentFilters": [
{
"action": "VIEW",
"data": [
{
"scheme": "https",
"host": "*.myapp.io",
"pathPrefix": "/notifications"
},
],
"category": [
"BROWSABLE",
"DEFAULT"
]
}
]