deferred deep linking - optimove-tech/Optimove-SDK-Android GitHub Wiki
Deep linking allows users to reach app content by clicking a link. This can be achieved even if the app is not installed.
Setup in Optimove
Go to settings and select 'Configuration' under the 'Deferred Deep Linking' heading to start.
Click 'Edit Configurations'
Enter the subdomain (of the lnk.click domain) that you want to use for your Deferred Deep Links.
To use Deferred Deep Links with your Android app, toggle the switch next to Android Config on. Enter the URL to your app in the Play Store, the Package for your app and the colon separated, SHA256 signing certificate fingerprint(s).
Note that if you are publishing to Google Play and app signing by Google Play is enabled, you need to add two SHA256 fingerprints: one obtained from signing APK locally and one obtained from Google Play console. Fingerprints are necessary for deep linking into your app without showing a disambiguation dialog.
Project setup
To integrate deep linking into your Android project, you have to complete the following steps.
The SDK uses Google Play's Install Referrer API to retrieve deferred deep link information when the app is first installed. This allows deep links to work even when the user doesn't have the app installed yet. Add the Install Referrer dependency: Add the following to your app's build.gradle file:
dependencies {
implementation 'com.android.installreferrer:installreferrer:2.2'
}
Add ProGuard rules: If you're using ProGuard or R8 for code obfuscation, add the following rules to your proguard-rules.pro file to ensure the Install Referrer API works correctly in release builds:
# Keep Install Referrer API classes for reflection checks
-keepnames class com.android.installreferrer.api.InstallReferrerClient
-keepnames class com.android.installreferrer.api.InstallReferrerStateListener
-keepnames class com.android.installreferrer.api.ReferrerDetails
Add an intent filter to your main activity:
<intent-filter android:label="deepLabel" android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Specify which URIs should be matched. Note, domain should be .lnk.click -->
<data android:scheme="https" android:host="subdomain.lnk.click"/>
</intent-filter>
Note that the subdomain you specify above should match the one you specified on the deep link configuration page on the Optimove UI.
Note that setting
android:autoVerify="true"will verify ownership of the domain, so, instead of offering a list of apps to select from your app will open automatically. No further actions are needed to enable this.
Add following overrides to the main activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Optimove.getInstance().seeIntent(getIntent(), savedInstanceState);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
Optimove.getInstance().seeInputFocus(hasFocus);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Optimove.getInstance().seeIntent(intent);
}
Configure a deep link handler:
OptimoveConfig config = new OptimoveConfig.Builder(
"<YOUR_OPTIMOVE_CREDENTIALS>","<YOUR_OPTIMOVE_MOBILE_CREDENTIALS>"
).enableDeepLinking(null, new MyDeferredDeepLinkHandler())
.build());
Optimove.initialize(this, config);
A stub implementation of the handler could be as follows:
public class MyDeferredDeepLinkHandler implements DeferredDeepLinkHandlerInterface {
public void handle(Context context, DeferredDeepLinkHelper.DeepLinkResolution resolution, String link, @Nullable DeferredDeepLinkHelper.DeepLink data){
//- Inspect the data payload and run code as needed.
}
}