링크를 통해 어플리케이션을 실행하고, 분기를 설정해 원하는 액티비티로 고객을 유도 할 수 있습니다.
1. Create Activity
링크를 통해 어플리케이션을 실행한 사용자가 처음 접근하게되는 Activity로, 사용자를 주소에따라 액티비티로 분기시키는데 사용됩니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DeepLinksActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
} | |
} |
생성한 DeepLinksActivity가 딥링크로 접속했을 때 실행되도록 설정합니다.
data에서 scheme와 host를 섞어 DeepLink주소를 완성하게 됩니다.
<scheme>://<host>/
ex)deeplink.test://myApplication/test/mycolor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<intent-filter> | |
<action android:name="android.intent.action.VIEW"/> | |
<data android:scheme="deeplink.test" android:host="myApplication" /> | |
<category android:name="android.intent.category.DEFAULT"/> | |
<category android:name="android.intent.category.BROWSABLE"/> | |
</intent-filter> |
기본적으로 아래와 같은 구조를 가집니다.
openDeepLink함수에서 if문을 통해 분기를 설정하고 Intent를 실행시켜줍니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DeepLinksActivity extends AppCompatActivity { | |
public static final String MYCOLOR_DEEP_LINK = "/test/mycolor"; | |
public static final String GOODCOLOR_DEEP_LINK = "/test2/goodcolor"; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
Intent intent = getIntent(); | |
if (intent == null || intent.getData() == null) { | |
finish(); | |
} | |
openDeepLink(intent.getData()); | |
finish(); | |
} | |
private void openDeepLink(Uri deepLink) { | |
String path = deepLink.getPath(); | |
if (MYCOLOR_DEEP_LINK.equals(path)) { | |
// Launch preferences | |
startActivity(new Intent(this, GetRGBInPhoto.class)); | |
} else if (GOODCOLOR_DEEP_LINK.equals(path)) { | |
// Launch the inbox activity | |
startActivity(new Intent(this, GoodColor.class)); | |
} else { | |
// Fall back to the main activity | |
startActivity(new Intent(this, MainActivity.class)); | |
} | |
} | |
} |
https://developers.google.com/app-indexing/android/test#---
위 주소로 접속한 뒤 아래와 같이 QR코드를 만들어줍니다.
생성한 QR코드를 읽어 URL을 클릭하면 정상적으로 Application의 원하는 intent가 시작된 것을 확인 할 수 있습니다.