To make custom links clickable on Android, you need to ensure that your app is set up to handle these links properly. This involves configuring your Android app to recognize and handle the custom URL scheme. Here are the steps you can follow:
You need to define an intent filter in your AndroidManifest.xml to handle your custom URL scheme. This will allow your app to be opened when a link with your custom scheme is clicked.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exampleapp">
<application
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|density|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="exampleApp" android:host="feed" />
</intent-filter>
</activity>
</application>
</manifest>
Replace exampleApp with your actual custom scheme and feed with the appropriate host if needed.
You need to handle the incoming intent in your React Native code to navigate to the appropriate screen when the link is clicked.
in App.js :
import React, { useEffect } from 'react';
import { Linking } from 'react-native';
const App = () => {
useEffect(() => {
const handleDeepLink = (event) => {
const url = event.url;
// Parse the URL and navigate to the appropriate screen
// Example: exampleApp://feed/123
const route = url.replace(/.*?:\/\//g, '');
const [feed, feedId] = route.split('/');
if (feed === 'feed' && feedId) {
// Navigate to the feed screen with the feedId
console.log(`Navigate to feed with ID: ${feedId}`);
}
};
// Add event listener for deep links
Linking.addEventListener('url', handleDeepLink);
// Check if the app was opened with a deep link
Linking.getInitialURL().then((url) => {
if (url) {
handleDeepLink({ url });
}
});
// Clean up the event listener
return () => {
Linking.removeEventListener('url', handleDeepLink);
};
}, []);
return (
// Your app component
);
};
export default App;
By following these steps, your custom links should become clickable on Android, allowing users to open your app directly from the link.
good luck ;)