This repository demonstrates the implementation of deep linking in an Android application using Jetpack Compose and Kotlin. With this functionality, users can enter the app through links entered in their browser.
- Deep Linking: Seamlessly navigate to specific parts of the app using browser links.
- Jetpack Compose: Utilizes Jetpack Compose for modern, declarative UI design.
- Kotlin: Written entirely in Kotlin, leveraging its powerful features for Android development.
-
Clone the repository:
git clone https://github.com/Bhavyansh03-tech/DeepLinking.git
-
Open the project in Android Studio:
- File > Open > Select the cloned project directory.
-
Build the project:
- Ensure that the necessary dependencies are downloaded and configured by building the project via Build > Make Project.
-
Define Deep Links:
- Deep links are defined in the
AndroidManifest.xml
file under the activity declaration or throughTools > ApplicationLinkAssistance > Create or add Link to it and then Test it
.
<activity android:name=".MainActivity" android:exported="true" android:theme="@style/Theme.DeepLinking"> <tools:validation testUrl="https://www.xiver.com" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter 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="https" /> <data android:host="www.xiver.com" /> </intent-filter> </activity>
- Deep links are defined in the
-
Handle Deep Links in Compose:
- Use
NavHost
andNavController
to handle navigation in Jetpack Compose based on the deep link.
class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { DeepLinkingTheme { val navController = rememberNavController() val uri = "https://www.xiver.com" NavHost( navController = navController, startDestination = "home" ){ composable( route = "home", deepLinks = listOf( navDeepLink { uriPattern = "$uri/{id}" } ) ){ backStackEntry -> val id = backStackEntry.arguments?.getString("id") Box( modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center ){ Text(text = id ?: "No id passed") } } } } } }
- Use
} ```
- Testing Deep Links:
- Open a browser and enter the URL that matches the deep link pattern defined in the manifest (e.g.,
https://www.example.com/path?id=123
).
- Open a browser and enter the URL that matches the deep link pattern defined in the manifest (e.g.,
MainActivity.kt
: The main entry point of the app.navigation/
: Contains navigation logic using Jetpack Compose.ui/
: Contains the composable functions and UI components.
Contributions are welcome! Please fork the repository and use a feature branch. Pull requests are warmly welcome.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a pull request
- Inspiration from various Android development tutorials and documentation.
For questions or feedback, please contact @Bhavyansh03-tech.