When a user with your app installed clicks an Adjust link, direct deep linking ensures they’re taken directly to specific content within the app.
Android provides two methods for receiving direct deep links. Within each method, you’ll pass the deep link to the Adjust SDK using one of the following methods:
Setup
Process and resolve deep link (recommended)
Use the processDeeplink method, which does the following:
- Records attribution from deep link clicks
- Resolves short branded links to their long branded link equivalent
- Passes through all other links as is
Your app can then handle the resolved link by parsing it and navigating to the appropriate screen. You can use this method for all deep links, including Adjust long branded links, other Android App Links, and app scheme deep links.
public static void processDeeplink(Uri url, Context context, OnDeeplinkResolvedListener callback)Process deep link (legacy)
The appWillOpenUrl method records attribution from deep link clicks if you’re not using short branded links.
public static void appWillOpenUrl(Uri url, Context context)The processDeeplink method supersedes this legacy method.
Implementation
Add the following code to your main activity to handle the deep link.
1class MainActivity : AppCompatActivity() {2 // Receive deep link when the Activity launches.3 override fun onCreate(savedInstanceState: Bundle?) {4 super.onCreate(savedInstanceState)5
6 // Get deep link from intent7 val incomingLink = intent?.data8 Log.d("IncomingLink", "onCreate: url=$incomingLink")9
10 if (incomingLink == null) return11
12 /*13 * Send deep link to Adjust's servers for attribution.14 * If short branded link, receive long link.15 * Otherwise, receive original link.16 */17 Adjust.processDeeplink(incomingLink, this) { resolvedLink ->18 if (resolvedLink == null) return@processDeeplink19 /*20 * Possible resolvedLink formats:21 *22 * 1. https://brandname.go.link/?adj_t=def456&23 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach24 * -> extract and decode the deep link from adj_link25 *26 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45627 * -> extract path from the URL28 *29 * 3. https://brandname.go.link/?adj_t=def456&30 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach31 * -> extract and decode the deep link from adj_deep_link32 * (used when Android app scheme path differs from iOS)33 *34 * 4. example://summer-clothes?promo=beach&adj_t=def45635 * -> extract path from the URL36 *37 * TODO: Handle the deep link and navigate to the appropriate screen.38 */39 }40 // Optional: prevent handling the same deep link multiple times41 intent.data = null42 }43
44 // Receive deep link in an existing Activity instance.45 override fun onNewIntent(intent: Intent) {46 super.onNewIntent(intent)47 setIntent(intent)48
49 // Get deep link from intent50 val incomingLink = intent?.data51 Log.d("IncomingLink", "onNewIntent: url=$incomingLink")52
53 if (incomingLink == null) return54
55 /*56 * Send deep link to Adjust's servers for attribution.57 * If short branded link, receive long link.58 * Otherwise, receive original link.59 */60 Adjust.processDeeplink(incomingLink, this) { resolvedLink ->61 if (resolvedLink == null) return@processDeeplink62 /*63 * Possible resolvedLink formats:64 *65 * 1. https://brandname.go.link/?adj_t=def456&66 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach67 * -> extract and decode the deep link from adj_link68 *69 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45670 * -> extract path from the URL71 *72 * 3. https://brandname.go.link/?adj_t=def456&73 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach74 * -> extract and decode the deep link from adj_deep_link75 * (used when Android app scheme path differs from iOS)76 *77 * 4. example://summer-clothes?promo=beach&adj_t=def45678 * -> extract path from the URL79 *80 * TODO: Handle the deep link and navigate to the appropriate screen.81 */82 }83 // Optional: prevent handling the same deep link multiple times84 intent.data = null85 }86
87}1public class MainActivity extends AppCompatActivity {2 // Receive deep link when the Activity launches.3 @Override4 protected void onCreate(Bundle savedInstanceState) {5 super.onCreate(savedInstanceState);6
7 // Get deep link from intent8 Intent appIntent = getIntent();9 Uri incomingLink = null;10 if (appIntent != null) {11 incomingLink = appIntent.getData();12 }13 Log.d("IncomingLink", "onCreate: url=" + incomingLink);14
15 if (incomingLink != null) {16 /*17 * Send deep link to Adjust's servers for attribution.18 * If short branded link, receive long link.19 * Otherwise, receive original link.20 */21 Adjust.processDeeplink(incomingLink, this, new OnDeeplinkResolvedListener() {22 @Override23 public void onDeeplinkResolved(String resolvedLink) {24 if (resolvedLink == null) {25 return;26 }27 /*28 * Possible resolvedLink formats:29 *30 * 1. https://brandname.go.link/?adj_t=def456&31 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach32 * -> extract and decode the deep link from adj_link33 *34 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45635 * -> extract path from the URL36 *37 * 3. https://brandname.go.link/?adj_t=def456&38 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach39 * -> extract and decode the deep link from adj_deep_link40 * (used when Android app scheme path differs from iOS)41 *42 * 4. example://summer-clothes?promo=beach&adj_t=def45643 * -> extract path from the URL44 *45 * TODO: Handle the deep link and navigate to the appropriate screen.46 */47 }48 });49 // Optional: prevent handling the same deep link multiple times50 appIntent.setData(null);51 }52 }53
54 // Receive deep link in an existing Activity instance.55 @Override56 protected void onNewIntent(Intent intent) {57 super.onNewIntent(intent);58 setIntent(intent); // Update the current intent with the new one59
60 Uri incomingLink = null;61 if (intent != null) {62 incomingLink = intent.getData();63 }64 Log.d("IncomingLink", "onNewIntent: url=" + incomingLink);65
66 if (incomingLink != null) {67 /*68 * Send deep link to Adjust's servers for attribution.69 * If short branded link, receive long link.70 * Otherwise, receive original link.71 */72 Adjust.processDeeplink(incomingLink, this, new OnDeeplinkResolvedListener() {73 @Override74 public void onDeeplinkResolved(String resolvedLink) {75 if (resolvedLink == null) {76 return;77 }78 /*79 * Possible resolvedLink formats:80 *81 * 1. https://brandname.go.link/?adj_t=def456&82 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach83 * -> extract and decode the deep link from adj_link84 *85 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45686 * -> extract path from the URL87 *88 * 3. https://brandname.go.link/?adj_t=def456&89 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach90 * -> extract and decode the deep link from adj_deep_link91 * (used when Android app scheme path differs from iOS)92 *93 * 4. example://summer-clothes?promo=beach&adj_t=def45694 * -> extract path from the URL95 *96 * TODO: Handle the deep link and navigate to the appropriate screen.97 */98 }99 });100 // Optional: prevent handling the same deep link multiple times101 intent.setData(null);102 }103 }104}Dedicated deep link activity
If you are using the Dedicated Deep Link Activity Approach, you also need to create a file such as the following:
1class DedicatedDeepLinkActivity : AppCompatActivity() {2 override fun onCreate(savedInstanceState: Bundle?) {3 super.onCreate(savedInstanceState)4 handleIntent(intent)5 }6
7 override fun onNewIntent(intent: Intent) {8 super.onNewIntent(intent)9 handleIntent(intent)10 }11
12 private fun handleIntent(intent: Intent) {13 Log.d("IncomingLink", "DedicatedDeepLinkActivity: url=${intent.data}")14
15 // Create intent to forward to MainActivity16 val mainActivityIntent = Intent(this, MainActivity::class.java).apply {17 data = intent.data18 putExtras(intent)19 addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)20 }21 startActivity(mainActivityIntent)22 finish()23 }24
25}1public class DedicatedDeepLinkActivity extends AppCompatActivity {2 @Override3 protected void onCreate(Bundle savedInstanceState) {4 super.onCreate(savedInstanceState);5 handleIntent(getIntent());6 }7
8 @Override9 protected void onNewIntent(Intent intent) {10 super.onNewIntent(intent);11 handleIntent(intent);12 }13
14 private void handleIntent(Intent intent) {15 Log.d("IncomingLink", "DedicatedDeepLinkActivity: url=" + intent.getData());16
17 // Create intent to forward to MainActivity18 Intent mainActivityIntent = new Intent(this, MainActivity.class);19 mainActivityIntent.setData(intent.getData());20 mainActivityIntent.putExtras(intent);21 mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);22
23 startActivity(mainActivityIntent);24 finish();25 }26}