Implement Deep Linking into an MDK Application
- How to handle deep link into MDK application
- How to use application
OnLinkDataReceivedevent - How to configure application links on SAP Mobile Services
Prerequisites
- Tutorial: Set Up for the Mobile Development Kit (MDK)
- Download the latest version of Mobile Development Kit SDK either from the SAP community trial download or SAP Software Center if you are a SAP Mobile Services customer. This is required you to build a branded client.
You may clone an existing metadata project from the MDK Tutorial GitHub repository and start directly with step 3 in this tutorial.
MDK supports deep linking into MDK applications using MDK client URL scheme and HTTP URLs via iOS Universal Links and Android App Links. iOS universal links and Android App Links are the HTTP URLs that bring the user directly to specific content in your MDK application.

- Step 1
This step includes creating a mobile project in SAP Build Lobby.
-
In the SAP Build Lobby, click Create > Create to start the creation process.

-
Click the Application tile and choose Next.

-
Select the Mobile category and choose Next.

-
Select the Mobile Application to develop your mobile project in SAP Business Application Studio and choose Next.

-
Enter the project name
deeplinkintomdkapp(used for this tutorial) , add a description (optional), and click Review.
SAP Build recommends the dev space it deems most suitable, and it will automatically create a new one for you if you don’t already have one. If you have other dev spaces of the Mobile Application type, you can select between them. If you want to create a different dev space, go to the Dev Space Manager. See Working in the Dev Space Manager.
-
Review the inputs under the Summary tab. If everything looks correct, click Create to proceed with creating your project.

-
Your project is being created in the Project table of the lobby. The creation of the project may take a few moments. After the project has been created successfully, click the project to open it.

-
The project opens in SAP Business Application Studio.

When you open the SAP Business Application Studio for the first time, a consent window may appear asking for permission to track your usage. Please review and provide your consent accordingly before proceeding.

-
- Step 2
The Storyboard provides a graphical view of the application’s runtime resources, external resources, UI of the application, and the connections between them. This allows for a quick understanding of the application’s structure and components.
- Runtime Resources: In the Runtime Resources section, you can see the mobile services application and mobile destination used in the project, with a dotted-line connected to the External Resources.
- External Resources: In the External Resources section, you can see the external services used in the project, with a dotted-line connection to the Runtime Resource or the UI app.
- UI Application: In the UI Applications section, you can see the mobile applications.
-
Click on + button in the Runtime Resources column to add a mobile services app to your project.

This screen will only show up when your CF login session has expired. Use either
CredentialsORSSO Passcodeoption for authentication. After successful signed in to Cloud Foundry, select your Cloud Foundry Organization and Space where you have set up the initial configuration for your MDK app and click Apply.
-
Choose
myapp.mdk.demofrom the applications list in the Mobile Application Services editor.
-
Select
com.sap.edm.sampleservice.v4from the destinations list and click Add App to Project.
You can access the mobile services admin UI by clicking on the Mobile Services option on the right hand side.
In the storyboard window, the app and mobile destination will be added under the Runtime Resources column. The mobile destination will also be added under the External Resources with a dotted-line connection to the Runtime Resource. The External Resource will be used to create the UI application.

-
Click the + button in the UI application column header to add mobile UI for your project.

-
In the Basic Information step, provide the below information and click Next. You will modify the generated project in next step and will deploy it later.
Field Value MDK Template TypeList DetailEnable Auto-Deployment to Mobile Services After Project CreationSelect No
The
List Detailtemplate generates the offline or online actions, rules, messages and pages to view records. More details on MDK template is available in help documentation. -
In the Data Collections step, provide the below information and click Finish. Data Collections step retrieves the entity sets information for the selected destination.
Field Value Enter a path to service (e.g. /sap/opu/odata/sap/SERVICE_NAME)Leave it as it is Select the Service TypeLeave the default value as ODataEnable OfflineIt’s enabled by default Select all data collectionsLeave it as it is What types of data will your application contain?Select CustomersandProducts
Regardless of whether you are creating an online or offline application, this step is needed for app to connect to an OData service. When building an MDK Mobile application, it assumes the OData service created and the destination that points to this service is set up in Mobile Services. For MDK Web application, destination is set up in SAP BTP admin UI.
Since you have Enable Offline set to Yes, the generated application will be offline enabled in the MDK Mobile client and will run as online in Web environment.
Data Collections step retrieves the entity sets information for the selected destination.
-
After clicking Finish, the storyboard is updated displaying the UI component. The MDK project is generated in the project explorer based on your selections.

- Step 3
MDK provides an
OnLinkDataReceivedevent in theApplication.appthat is called when the MDK app is launched from an external link. The data can be accessed viacontext.getAppEventData().-
Click the Application.app to open it in MDK Application Editor and then and select the
Create a rule/actionfor theOnLinkDataReceivedevent.
-
Select the Object Type as Rule and keep the default Folders path.

-
In the Basic Information step, enter the Rule name as
LinkDataReceivedand click Finish to complete the rule creation process.
-
Replace the generated code with below snippet.
JavaScriptCopy/** * Describe this function... * @param {IClientAPI} context */ export default function LinkDataReceived(context) { context.getLogger().log(`Link Data Received Triggered`,'Info'); let linkData = context.getAppEventData(); let data; try { data = JSON.parse(linkData); } catch (error) { return null; } let splitURL = data.URL.split('/'); let action = splitURL[3]; let entity = splitURL.length > 4 ? splitURL[4] : ''; switch (action) { case 'search': if (entity === 'product') { return openProductListWithFilter(context, data.Parameters); } break; case 'product': if (data.Parameters && data.Parameters.id) { return openProductByID(context, data.Parameters.id); } break; default: context.getLogger().log(`Unrecognized Link Path ${data.URL}`,'Error'); break; } } function openProductByID(context, id) { context.getLogger().log(`ID: ${id}`,'Debug'); return context.read('/deeplinkintomdkapp/Services/com_sap_edm_sampleservice_v4.service', `Products(${id})`, [], null).then(function (result) { if (result.length) { context.getPageProxy().setActionBinding(result.getItem(0)); return context.getPageProxy().executeAction('/deeplinkintomdkapp/Actions/com_sap_edm_sampleservice_v4/Products/NavToProducts_Detail.action'); } }); } function openProductListWithFilter(context, parametersObj) { let pageData = context.getPageProxy().getPageDefinition('/deeplinkintomdkapp/Pages/com_sap_edm_sampleservice_v4_Products/Products_List.page'); var filterQO = '$filter='; for (var key in parametersObj) { var value = parametersObj[key]; filterQO += `${key} eq '${value}' and `; } if (filterQO.slice(-5) === ' and ') { filterQO = filterQO.slice(0, filterQO.length - 5); } context.getLogger().log(`${filterQO}`,'Debug'); pageData.Controls[0].Sections[0].Target.QueryOptions = filterQO; return context.getPageProxy().executeAction({ "Name": '/deeplinkintomdkapp/Actions/com_sap_edm_sampleservice_v4/Products/NavToProducts_List.action', "Properties": { "PageMetadata": pageData } }); }
-
- Step 4
Now that the MDK application is configured to act when a request from external source is received, you will Deploy the Project definitions to Mobile Services to use in the Mobile client.
-
Switch to the
Application.apptab, click the Deploy option in the editor’s header area, and then choose the deployment target as Mobile Services.
-
Select deploy target as Mobile Services.

If you want to enable source for debugging the deployed bundle, then choose Yes.

You should see Deploy to Mobile Services successfully! message.

MDK supports deep linking into MDK applications using
-
- Step 5
- Step 6
-
Follow steps 1 to 3 from this tutorial and make sure to use the same bundle ID in
MDKProject.jsonas you provided for Apple Universal Links settings in Mobile Services and also for Application ID in Android Studio while generating Digital Asset Links file. -
Add highlighted files under
DemoSampleApp.mdkproject.DemoSampleApp.mdkproject ├── App_Resources_Merge ├── Android │ └── src │ └── main │ └── AndroidManifest.xml └── iOS ├── app.entitlements └── build.xcconfig
Files specified in the
.mdkproject/App_Resources_Mergefolder override a part of the files in<generated-project>/app/App_Resources. You can find more details about it in help documentation. -
Provide below information in the
AndroidManifest.xmlfile. Make sure to provide Server URL from the step 4.2 and save the changes.XMLCopy<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <application> <activity android:name="sap.mdkclient.MDKAndroidActivity"> <intent-filter android:autoVerify="true"> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="https" /> <data android:host="<enter Server URL without https:// from step 4.2>" /> <data android:pathPrefix="/mobileservices/deeplinks" /> </intent-filter> </activity> </application> </manifest>The intent files will map URLs from your website to activities to your MDK Client so the
OnLinkDataReceivedevent can be triggered. See here for more information. -
Provide below information in the
app.entitlementsfile. Make sure to provide Server URL from the step 4.2 and save the changes.XMLCopy<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>aps-environment</key> <string>development</string> <key>com.apple.developer.associated-domains</key> <array> <string>applinks:<enter Server URL without https:// from the step 4.2></string> </array> <key>com.apple.security.app-sandbox</key> <true/> <key>com.apple.security.network.client</key> <true/> </dict> </plist> -
Provide below information in the
build.xcconfigfile. Make sure to provide same Apple Team ID that you entered in Mobile Services Apple Universal Links configuration.XMLCopy// Specify the Team since Universal links are specific to the Team / Bundle ID configured in Mobile Services DEVELOPMENT_TEAM = <Your Team ID> -
Create your MDK client either using MDK SDK by following the step 4 from Build Your Mobile Development Kit Client Using MDK SDK tutorial OR using SAP Cloud Build Service by following Build Your Mobile Development Kit Client Using Cloud Build Service tutorial.
-
- Step 7
Make sure you are choosing the right device platform tab above.
- Step 8
Make sure you are choosing the right device platform tab above.
In a real-world use case, you would click on a link from external sources such as webpage, email, or another app. This action will launch your MDK client and enable tasks such as navigating to a page, filtering a list based on a parameter, or approving a request.
For this tutorial, to test the deep links, you will download an
index.htmlon your local machine and place it in your device’s file system.