React-native-track-player: Custom Notification onClick event

Created on 13 Nov 2018  路  4Comments  路  Source: react-native-kit/react-native-track-player

We want to navigate to player screen on notification click. Is there any solution?

Android Enhancement

Most helpful comment

I've added the URI trackplayer://notification.click, it will be triggered when the notification is clicked. Read about how to handle it in linking.

All 4 comments

I've added the URI trackplayer://notification.click, it will be triggered when the notification is clicked. Read about how to handle it in linking.

There are two conditions you should know:

  • The app is already open and the notification is clicked
// This event will be fired
Linking.addEventListener('url', (data) => console.log(data.url));
  • The app is closed (stopWithApp is set to false) and the notification is clicked
// You have to retrieve the URL manually
Linking.getInitialURL().then(url => console.log(url));

Here's an example that handles both conditions:

class App extends Component {
    componentDidMount() {
        Linking.getInitialURL().then((url) => this.handleUrl({url: url}));
        Linking.addEventListener('url', this.handleUrl);
    }

    componentWillUnmount() {
        Linking.removeEventListener('url', this.handleUrl);
    }

    handleUrl = (data) => {
        if (data.url === 'trackplayer://notification.click') {
            // Do something
        }
    };
}

Is it just for android? It doesn't work in IOS ..

yeah, looking at the sources it seems this is only implemented for Android.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

amed picture amed  路  4Comments

elioscordo picture elioscordo  路  3Comments

EhteshamAnwar picture EhteshamAnwar  路  3Comments

mckmarc picture mckmarc  路  4Comments

tarahiw picture tarahiw  路  3Comments