In this tutorial i will show a way of using MobileDeepLinking in your app.
To use App deeplinking in your app to you need to setup your manifet to do so
Lets start with it:
Edit your manifest and add
to it.
mydeep in this case is the deeplinking scheme i added for my tests...
To make use of the Activity org.mobiledeeplinking.android.MobileDeepLinking you need to use the attached B4A Library (MobileDeeplinking). See Example too
In this tutorial i will show you a way to get dynamic (not really as a file must be placed in assets. But you can update your app to get a new config file to use) deeplinking based on an json file which configures all deeplinks. You can see at the deeplinking lib as kind of a "router for your apps deeplinks".
assets/mobiledeeplinkingconfig.json
But if you use the url "mydeep://product/123/4567" this will call the main activity too but provides some kind of pairing the url to variables (kind of)
In this case the productID is set to 123 and the customerID is set to 4567. This is delegated/routed to the activity de.donmanfred.deeplinking.main
If you use the url "mydeep://order/ABCDEF" it will set the orderID to ABCDEF and call the Activity
de.donmanfred.deeplinking.orders (Activity orders in example)
For more informations on what you can do with the json please refer to the original sites documentation!
Main Activity
Activity orders
If you want to donate for my work building the wrapper and this tutorial you can do it here:
To use App deeplinking in your app to you need to setup your manifet to do so
Lets start with it:
Edit your manifest and add
B4X:
AddApplicationText(<activity
android:name="org.mobiledeeplinking.android.MobileDeepLinking"
android:theme="@android:style/Theme.NoDisplay"
android:noHistory="true">
<intent-filter>
<data android:scheme="mydeep"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>)
mydeep in this case is the deeplinking scheme i added for my tests...
To make use of the Activity org.mobiledeeplinking.android.MobileDeepLinking you need to use the attached B4A Library (MobileDeeplinking). See Example too
In this tutorial i will show you a way to get dynamic (not really as a file must be placed in assets. But you can update your app to get a new config file to use) deeplinking based on an json file which configures all deeplinks. You can see at the deeplinking lib as kind of a "router for your apps deeplinks".
assets/mobiledeeplinkingconfig.json
defaultRoute: If no route matches then this activity will be started. In this case the Main activity of the provided example. It´s like calling the url "mydeep://somewhat"{
"logging": "true",
"defaultRoute": {
"class": "de.donmanfred.deeplinking.main"
},
"routes": {
"product/roductID/:customerID": {
"handlers": ["testHandler"],
"name": "Product",
"class": "de.donmanfred.deeplinking.main",
"routeParameters" : {
"productID" : {
"regex": "[0-9][0-9]?[0-9]?[0-9]?"
},
"customerID" : {
"regex": "[0-9][0-9]?[0-9]?[0-9]?"
}
}
},
"order/rderID": {
"handlers": ["testHandler"],
"name": "Product",
"class": "de.donmanfred.deeplinking.orders",
"routeParameters" : {
"orderID" : {
"regex": "[0-9a-zA-Z]{0,10}"
}
}
}
}
}
But if you use the url "mydeep://product/123/4567" this will call the main activity too but provides some kind of pairing the url to variables (kind of)
In this case the productID is set to 123 and the customerID is set to 4567. This is delegated/routed to the activity de.donmanfred.deeplinking.main
If you use the url "mydeep://order/ABCDEF" it will set the orderID to ABCDEF and call the Activity
de.donmanfred.deeplinking.orders (Activity orders in example)
For more informations on what you can do with the json please refer to the original sites documentation!
Main Activity
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim deeplink As MobileDeepLinking
Dim lastIntent As Intent
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
deeplink.Initialize("","testHandler")
'Dim json As String = File.ReadString(File.DirAssets,"config2.json")
'deeplink.Configuration = json
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_VIEW, "mydeep://order/ABCDEF") ' Will open Activity orders and the starting intent holds the orderID ABCDEF
StartActivity(Intent1)
'Dim Intent1 As Intent
'Intent1.Initialize(Intent1.ACTION_VIEW, "mydeep://product/123/4567") ' Will open the main activity and the starting intent holds
' productID=123 and customerID=4567
'StartActivity(Intent1)
End Sub
Sub Activity_Resume
Dim i As Intent = Activity.GetStartingIntent
If i <> Null Then
If i <> lastIntent Then
lastIntent = i
Log("Action="&i.Action)
If i.Action = "DeepLink" Then
If i.HasExtra("productID") Then
Log("productID="&i.GetExtra("productID"))
End If
If i.HasExtra("customerID") Then
Log("customerID="&i.GetExtra("customerID"))
End If
End If
End If
End If
End Sub
Activity orders
B4X:
Sub Activity_Resume
Dim i As Intent = Activity.GetStartingIntent
If i <> Null Then
If i <> lastIntent Then
lastIntent = i
Log("Action="&i.Action)
If i.Action = "DeepLink" Then
If i.HasExtra("orderID") Then
Log("orderID="&i.GetExtra("orderID"))
End If
End If
End If
End If
End Sub
If you want to donate for my work building the wrapper and this tutorial you can do it here: