I have been trying to open an application through a web browser on my Android phones (both emulator and psychical device). Anytime when I put 'mydeeplink://people/0' as URL it just starts searching on google for the query instead of opening the app.
I personally think that I didn't configure one of the Google flags correctly. I left it all on default, because I didn't found anybody mentioning flags corresponding to deep links on the internet.
I already tried adding node-tools to the intent-filter after 'android:label="filter_react_native"'
I followed a tutorial from this website, however it seems to be outdated
this is my code:
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mydeeplink">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="filter_react_native"
android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="mydeeplink" android:host="people" />
</intent-filter>
</activity>
<activity
android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
</manifest>
index.android.js:
// index.ios.js or index.android.js
import { AppRegistry } from 'react-native';
import Router from './router';
AppRegistry.registerComponent('mydeeplink', () => Router);
home.js:
import React from 'react';
import { Platform, Text, Linking } from 'react-native';
class Home extends React.Component {
static navigationOptions = { // A
title: 'Home',
};
componentDidMount() { // B
if (Platform.OS === 'android') {
Linking.getInitialURL().then(url => {
this.navigate(url);
});
} else {
Linking.addEventListener('url', this.handleOpenURL);
}
}
componentWillUnmount() { // C
Linking.removeEventListener('url', this.handleOpenURL);
}
handleOpenURL = (event) => { // D
this.navigate(event.url);
}
navigate = (url) => { // E
const { navigate } = this.props.navigation;
const route = url.replace(/.*?:\/\//g, '');
const id = route.match(/\/([^\/]+)\/?$/)[1];
const routeName = route.split('/')[0];
if (routeName === 'people') {
navigate('People', { id, name: 'chris' })
};
}
render() {
return <Text>Hello from Home!</Text>;
}
}
export default Home;
router.js:
import React from 'react';
import {
AppRegistry,
Text,
} from 'react-native';
import { createStackNavigator } from 'react-navigation-stack';
import { createAppContainer } from 'react-navigation';
import Home from './home';
import People from './people';
const Router = createStackNavigator(
{
Home: Home,
Details: People,
},
{
initialRouteName: 'Home',
}
) ;
const AppContainer = createAppContainer(Router);
export default class App extends React.Component{
render(){
return <AppContainer/>
}
}
It's expected to open my React-Native app and open a picture of Leela. Currently the query just searched for the query on the world wide web in google chrome on both emulator as physical device