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