
Hii Developer in this Android example we are a description of Android deep linking. What is deep linking and how to work it?
What is Deep linking?
Deeplinks are a concept that helps users navigate between the web and mobile App. They are basically URLs that navigate users directly to the specific content in your Android App.
How to Work Android Deep linking:-
When a user clicked URL, the Android system tries each of the following actions, in sequential order, until the request succeeds
- Open the user’s preferred app that can handle the URI, if one is designated.
- Open the only available app that can handle the URI.
- Allow the user to select an app from a dialog
For these, you can use Android Intent fillet to define a specific Screen to of app open on the link click.
How to define intent filters
When we talk about handling how to navigate users directly to specific content in You App, we should think about adding an intent filter in our manifest file. An intent filter should contain the following elements and attribute values;
- Define
ACTION_VIEW
intent action so that the intent filter can be reached from Google Search.
<action android:name="android.intent.action.VIEW" />
2. We should include the BROWSABLE
category in order to be accessible from a web browser. We should also have DEFAULT a category for responding to implicit intents
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
3. Lastly, We should define one or more <data>
tags. Each of these tags represents a URI format that resolves to the activity. The following example represents a simple data tag for the codeplayon.com Android app.
<data
android:host="codeplayon.com"
android:scheme="https" />
How to Get data from incoming intents in Your Activity?
When you define your intent filter that can handle specific URLs, the system can start your activity via that intent filter.
Intent intent = getIntent();
Uri data = intent.getData();
So Let Make A Fine Simple Example For your Android App Follow these code.
Step 1. we should think about adding an intent filter in our manifest file.
<activity android:name=".DeepLinkingScreen" android:theme="@style/AppTheme.NoActionBar"> <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:host="codeplayon.com" android:pathPrefix="/" android:scheme="https" /> </intent-filter> </activity>
Step 2: Add these in Your Java Class.
Intent intent=getIntent(); if(intent!=null&&intent.getData()!=null ){ Uri uri = Uri.parse(intent.getData().toString()); path = uri.getPath(); GetDetails(path); }
In You Want get more form ULR you used this parameter
Uri uri = Uri.parse("https://www.codeplayon.com/post.html?chapter=V-Maths-Addition%20&%20Subtraction&post=394");
String server = uri.getAuthority();
String path = uri.getPath();
String protocol = uri.getScheme();
Set<String> args = uri.getQueryParameterNames();