mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-26 07:04:05 +08:00
Add deep linking support to IntentAndroid
Summary:
Add a method to handle URLs registered to the app,
```js
IntentAndroid.getInitialURL(url => {
if (url) {
// do stuff
}
});
```
Refer - http://developer.android.com/training/app-indexing/deep-linking.html#adding-filters
The API cannot be same as the iOS API (i.e. as a constant), as the activity is not availble at the time of module initialization. Moreover, multiple activties can share the same bridge instance, and the activity itself is not a constant. Hence the initialURL can change.
Closes https://github.com/facebook/react-native/pull/4320
Reviewed By: svcscm
Differential Revision: D2759667
Pulled By: foghina
fb-gh-sync-id: b725231ae1401fa5565d444eee5a30d303e263ae
This commit is contained in:
committed by
facebook-github-bot-5
parent
cf94a9ea95
commit
eb188c8d98
@@ -16,6 +16,26 @@ var invariant = require('invariant');
|
||||
/**
|
||||
* `IntentAndroid` gives you a general interface to handle external links.
|
||||
*
|
||||
* ### Basic Usage
|
||||
*
|
||||
* #### Handling deep links
|
||||
*
|
||||
* If your app was launched from an external url registered to your app you can
|
||||
* access and handle it from any component you want with
|
||||
*
|
||||
* ```
|
||||
* componentDidMount() {
|
||||
* var url = IntentAndroid.getInitialURL(url => {
|
||||
* if (url) {
|
||||
* console.log('Initial url is: ' + url);
|
||||
* }
|
||||
* });
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* NOTE: For instructions on how to add support for deep linking,
|
||||
* refer [Enabling Deep Links for App Content - Add Intent Filters for Your Deep Links](http://developer.android.com/training/app-indexing/deep-linking.html#adding-filters).
|
||||
*
|
||||
* #### Opening external links
|
||||
*
|
||||
* To start the corresponding activity for a link (web URL, email, contact etc.), call
|
||||
@@ -75,6 +95,20 @@ class IntentAndroid {
|
||||
IntentAndroidModule.canOpenURL(url, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the app launch was triggered by an app link with {@code Intent.ACTION_VIEW},
|
||||
* it will give the link url, otherwise it will give `null`
|
||||
*
|
||||
* Refer http://developer.android.com/training/app-indexing/deep-linking.html#handling-intents
|
||||
*/
|
||||
static getInitialURL(callback: Function) {
|
||||
invariant(
|
||||
typeof callback === 'function',
|
||||
'A valid callback function is required'
|
||||
);
|
||||
IntentAndroidModule.getInitialURL(callback);
|
||||
}
|
||||
|
||||
static _validateURL(url: string) {
|
||||
invariant(
|
||||
typeof url === 'string',
|
||||
|
||||
Reference in New Issue
Block a user