Deep linking between Native Android and React Native

We are working with two different apps, one is native built with Android Java and the other built with React Native. One of the feature required us to invoke the React Native app from Native Android app and then jump to a specific screen in it.

We have accomplished this feature which is essentially deep linking with help of Intents . In this article, we’ll share about how we went about doing this.

To receive an intent from an external app, we need to add an intent filter that contains the following elements and attribute values to your manifest file.

To start, you need to pick an Activity within your app that you’d like to open when the URI scheme is triggered and register an intent filter for it.

Schememust be unique. If it overlaps with a different app’s URI scheme, the user will see an Android chooser when clicking on the link letting them choose which app to forward the trigger to.

Handling deep linking in the native Android app

Calling the getData() and getAction() methods lets you retrieve the data and action associated with the incoming Intent.

Handling deep link in the React Native app

  • In React Native, there is a more eloquent way to implement this using the Linking API . With the help of getInitialURL() and listener methods, We can handle it as shown below:
  • getInitialURL() – If the app is launched by external link, then this method will get invoked.
  • Linking.addEventListener(‘url’,handler) – A listener method to receive url from the external app where we already embedded scheme and host.
  • Here we receive and check the url from external native app, based on this url we can navigate to different screen in React Native app.

To set the deep link in Android App

Action: all Intents are called as View action — ACTION_VIEW

URI: intents use URI encoded strings that specify a desired action along with some data which to perform an action.

One more thing: We can also use a simple adb command to test this like so –

$ adb shell am start
-W -a android.intent.action.VIEW
-d "link://exampleurl" com.shooter

This might help you to implement deep linking in React Native & native Android. Thanks to my friend Prabakaran for helping me to get the React Native app part done.

We are people from Spritle and weto build awesome apps using Rails, Node JS, Android, Swift, React Native and so on. to hire our kick-ass team that can bring your ideas to reality.

稿源:Spritle (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » Deep linking between Native Android and React Native

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录