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 processAndResolveDeeplink 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 processAndResolveDeeplink(AdjustDeeplink adjustDeeplink, Context context, OnDeeplinkResolvedListener callback)Process deep link (legacy)
The processDeeplink method records attribution from deep link clicks if you’re not using short branded links.
public static void processDeeplink(AdjustDeeplink adjustDeeplink, Context context)The processAndResolveDeeplink 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 // Create deep link object13 val deeplink = AdjustDeeplink(incomingLink)14
15 /*16 * Send deep link to Adjust's servers for attribution.17 * If short branded link, receive long link.18 * Otherwise, receive original link.19 */20 Adjust.processAndResolveDeeplink(deeplink, this) { resolvedLink ->21 if (resolvedLink == null) return@processAndResolveDeeplink22 /*23 * TODO: Handle the deep link and navigate to the appropriate screen.24 *25 * Possible resolvedLink formats:26 *27 * 1. https://brandname.go.link/?adj_t=def456&28 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach29 * -> extract and decode the deep link from adj_link30 *31 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45632 * -> extract path from the URL33 *34 * 3. https://brandname.go.link/?adj_t=def456&35 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach36 * -> extract and decode the deep link from adj_deep_link37 * (used when Android app scheme path differs from iOS)38 *39 * 4. example://summer-clothes?promo=beach&adj_t=def45640 * -> extract path from the URL41 */42 }43 // Optional: prevent handling the same deep link multiple times44 intent.data = null45 }46
47 // Receive deep link in an existing Activity instance.48 override fun onNewIntent(intent: Intent) {49 super.onNewIntent(intent)50 setIntent(intent)51
52 // Get deep link from intent53 val incomingLink = intent?.data54 Log.d("IncomingLink", "onNewIntent: url=$incomingLink")55
56 if (incomingLink == null) return57
58 // Create deep link object59 val deeplink = AdjustDeeplink(incomingLink)60
61 /*62 * Send deep link to Adjust's servers for attribution.63 * If short branded link, receive long link.64 * Otherwise, receive original link.65 */66 Adjust.processAndResolveDeeplink(deeplink, this) { resolvedLink ->67 if (resolvedLink == null) return@processAndResolveDeeplink68 /*69 * TODO: Handle the deep link and navigate to the appropriate screen.70 *71 * Possible resolvedLink formats:72 *73 * 1. https://brandname.go.link/?adj_t=def456&74 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach75 * -> extract and decode the deep link from adj_link76 *77 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45678 * -> extract path from the URL79 *80 * 3. https://brandname.go.link/?adj_t=def456&81 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach82 * -> extract and decode the deep link from adj_deep_link83 * (used when Android app scheme path differs from iOS)84 *85 * 4. example://summer-clothes?promo=beach&adj_t=def45686 * -> extract path from the URL87 */88 }89 // Optional: prevent handling the same deep link multiple times90 intent.data = null91 }92}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 // Create deep link object17 AdjustDeeplink deeplink = new AdjustDeeplink(incomingLink);18
19 /*20 * Send deep link to Adjust's servers for attribution.21 * If short branded link, receive long link.22 * Otherwise, receive original link.23 */24 Adjust.processAndResolveDeeplink(deeplink, this, new OnDeeplinkResolvedListener() {25 @Override26 public void onDeeplinkResolved(String resolvedLink) {27 if (resolvedLink == null) {28 return;29 }30 /*31 * TODO: Handle the deep link and navigate to the appropriate screen.32 *33 * Possible resolvedLink formats:34 *35 * 1. https://brandname.go.link/?adj_t=def456&36 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach37 * -> extract and decode the deep link from adj_link38 *39 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45640 * -> extract path from the URL41 *42 * 3. https://brandname.go.link/?adj_t=def456&43 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach44 * -> extract and decode the deep link from adj_deep_link45 * (used when Android app scheme path differs from iOS)46 *47 * 4. example://summer-clothes?promo=beach&adj_t=def45648 * -> extract path from the URL49 */50 }51 });52 // Optional: prevent handling the same deep link multiple times53 appIntent.setData(null);54 }55 }56
57 // Receive deep link in an existing Activity instance.58 @Override59 protected void onNewIntent(Intent intent) {60 super.onNewIntent(intent);61 setIntent(intent); // Update the current intent with the new one62
63 Uri incomingLink = null;64 if (intent != null) {65 incomingLink = intent.getData();66 }67 Log.d("IncomingLink", "onNewIntent: url=" + incomingLink);68
69 if (incomingLink != null) {70 // Create deep link object71 AdjustDeeplink deeplink = new AdjustDeeplink(incomingLink);72
73 /*74 * Send deep link to Adjust's servers for attribution.75 * If short branded link, receive long link.76 * Otherwise, receive original link.77 */78 Adjust.processAndResolveDeeplink(deeplink, this, new OnDeeplinkResolvedListener() {79 @Override80 public void onDeeplinkResolved(String resolvedLink) {81 if (resolvedLink == null) {82 return;83 }84 /*85 * TODO: Handle the deep link and navigate to the appropriate screen.86 *87 * Possible resolvedLink formats:88 *89 * 1. https://brandname.go.link/?adj_t=def456&90 * adj_link=https%3A%2F%2Fexample.com%2Fsummer-clothes%3Fpromo%3Dbeach91 * -> extract and decode the deep link from adj_link92 *93 * 2. https://brandname.go.link/summer-clothes?promo=beach&adj_t=def45694 * -> extract path from the URL95 *96 * 3. https://brandname.go.link/?adj_t=def456&97 * adj_deep_link=example%3A%2F%2Fsummer-clothes%3Fpromo%3Dbeach98 * -> extract and decode the deep link from adj_deep_link99 * (used when Android app scheme path differs from iOS)100 *101 * 4. example://summer-clothes?promo=beach&adj_t=def456102 * -> extract path from the URL103 */104 }105 });106 // Optional: prevent handling the same deep link multiple times107 intent.setData(null);108 }109 }110}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_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)20 }21 startActivity(mainActivityIntent)22 finish()23 }24}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_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);22
23 startActivity(mainActivityIntent);24 finish();25 }26}