MovableInk Link Resolution without SDK
If you are not adding the SDK as a dependency in your project, here are some steps to resolve MovableInk Links.
Step One: Enable deeplinking
Step Two: Fetching the Re-direct URL
The Movable -Ink links use url forwarding/redirects. To get the final clickthrough , you will need to follow
the redirects until you get a Success
response code
val client = OkHttpClient.Builder()
.followRedirects(true) // this is true by default
.build()
var request = Request.Builder()
.url(MOVABLE_URL)
.build()
okHttpClient.newCall(request).enqueue(object : Callback {
override fun onResponse(call: Call, response: Response) {
if (response.code == 200) {
val clickThroughUrl: URL = (response.request.url).toUrl()
}
}
override fun onFailure(call: Call, e: IOException) {
// handle failures
}
})
fun fetchClickThrough() {
val url = URL(MOVABLE_URL)
var connection = url.openConnection() as HttpURLConnection
connection.instanceFollowRedirects = true
connection.connect()
var responseCode = connection.responseCode
if (responseCode == HttpURLConnection.HTTP_OK) {
// Process the response here
val clickThroughURL:URL = connection.url
}
}
Note
Depending on your project set-up if you are not handling redirects automatically , you will need to loop through the request/response cycle until you receive a non-redirect response.
This typically involves checking the response status code and headers for redirect information (e.g. the new location of the resource), updating the request URL or headers accordingly, and making the request again.
Step Three: Using the Clickthrough URL
Movable-Ink supports the standard HTTP/HTTPS
URLs as well as custom URIs.
This in-turn means that after retrieving the final clickthrough URL you can use it in your app to link to a specific screen or content within the app.