앱이 설치된 사용자가 Adjust 링크를 클릭하면 다이렉트 딥링킹을 통해 앱 내의 특정 콘텐츠로 바로 이동할 수 있습니다.
Android는 다이렉트 딥링크를 수신하는 두 가지 메서드를 제공합니다. 각 메서드에서는 다음 메서드 중 하나를 사용하여 Adjust SDK에 딥링크를 전달할 수 있습니다.
설정
딥링크 처리 및 확인(권장)
processAndResolveDeeplink 메서드를 사용하여 다음 작업을 수행합니다.
- 딥링크 클릭에서 어트리뷰션 기록
- 단축 브랜드 링크를 이에 상응하는 긴 브랜드 링크로 변환
- 다른 모든 링크를 그대로 전달
앱은 해결된 링크를 분석하여 적절한 화면으로 이동함으로써 처리할 수 있습니다. Adjust의 긴 브랜드 링크, 기타 Android 앱 링크, APP SCHEME 딥링크를 포함한 모든 딥링크에 이 메서드를 사용할 수 있습니다.
public static void processAndResolveDeeplink(AdjustDeeplink adjustDeeplink, Context context, OnDeeplinkResolvedListener callback)딥링크 처리(레거시)
processDeeplink 메서드는 단축 브랜드 링크를 사용하지 않는 경우 딥링크 클릭으로부터의 어트리뷰션을 기록합니다.
public static void processDeeplink(AdjustDeeplink adjustDeeplink, Context context)processAndResolveDeeplink 메서드가 이 레거시 메서드를 대체합니다.
구현
다음의 코드를 메인 액티비티에 추가하여 딥링크를 처리합니다.
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}전용 딥링크 액티비티
전용 딥링크 액티비티 접근법을 사용하는 경우 다음과 같은 파일도 생성해야 합니다.
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}