Deeplink

Android

Users can deep link through to the booking screen by adding an intent-filter to the relevant activity of their app in the AndroidManifest and the code to retrieve the data and construct the BookingActivity as detailed in the Android developer guide.

<!-- Booking deep linking -->
<intent-filter>
		<action android:name="android.intent.action.VIEW" />
		<category android:name="android.intent.category.DEFAULT" />
		<category android:name="android.intent.category.BROWSABLE" />
		<data
			android:host="karhoo.app"
			android:pathPattern="/location"
			android:scheme="https" />
</intent-filter>

<!-- Trip tracking deep linking -->
<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:host="karhoo.app"
			android:pathPattern="/triptracking"
			android:scheme="https" />
</intent-filter>

Get the data to construct the JourneyInfo (for the Booking Screen) or the TripInfo (for trip tracking) from the Intent

//Get the booking deep link data from the intent
intent?.data?.apply {
		val origin = getQueryParameter(ORIGIN_LATITUDE)?.let { latitude ->
				getQueryParameter(ORIGIN_LONGITUDE)?.let { longitude ->
						Position(latitude = latitude.toDouble(), longitude = longitude.toDouble())
				}
		}
		val destination = getQueryParameter(DESTINATION_LATITUDE)?.let { latitude ->
				getQueryParameter(DESTINATION_LONGITUDE)?.let { longitude ->
						Position(latitude = latitude.toDouble(), longitude = longitude.toDouble())
				}
		}
		val dateTime = getQueryParameter(DATE_TIME)?.let {
				DateTime.parse(it, DateTimeFormat.forPattern("yyyy-MM-dd HH:mm"))
		}
		journeyInfo = JourneyInfo(origin, destination, dateTime)
} ?: run { journeyInfo = null }


//Get the trip tracking deep link data from the intent
intent?.data?.apply {
		val tripId = getQueryParameter(TRIP_ID)?.let { it }
		tripId?.let {
				val origin = getQueryParameter(ORIGIN_LATITUDE)?.let { latitude ->
						getQueryParameter(ORIGIN_LONGITUDE)?.let { longitude ->
								getQueryParameter(ORIGIN_DISPLAY_ADDRESS)?.let { display_address ->
								val pos = Position(
										latitude = latitude.toDouble(), longitude = = longitude.toDouble()
								)
							TripLocationInfo(position = pos, displayAddress = display_address)
						}
				}
		}
		val destination = getQueryParameter(DESTINATION_LATITUDE)?.let { latitude ->
				getQueryParameter(DESTINATION_LONGITUDE)?.let { longitude ->
						getQueryParameter(DESTINATION_DISPLAY_ADDRESS)?.let { display_address ->
								val pos = Position(
										latitude = latitude.toDouble(), longitude = = longitude.toDouble()                                    )
								TripLocationInfo(position = pos, displayAddress = display_address)
						}
				}
		}
		tripInfo = TripInfo(tripId = tripId, origin = origin, destination = destination)
		}
} ?: run { tripInfo = null }

//These can be changed to match the parameter names used in the deep link
companion object {
        private const val ORIGIN_LATITUDE = "origin_latitude"
        private const val ORIGIN_LONGITUDE = "origin_longitude"
        private const val DESTINATION_LATITUDE = "destination_latitude"
        private const val DESTINATION_LONGITUDE = "destination_longitude"
        private const val DATE_TIME = "date_time"
        private const val TRIP_ID = "trip_id"
        private const val ORIGIN_DISPLAY_ADDRESS = "origin_display_address"
        private const val DESTINATION_DISPLAY_ADDRESS = "destination_display_address"
}

The use the JourneyInfo or TripInfo when building the BookingActivity

//Use the JourneyInfo created when starting the BookingActivity       
val builder = BookingActivity.Builder.builder
                        .initialLocation(location)
                        .journeyInfo(journeyInfo)
												.tripInfo(tripInfo)
startActivity(builder.build(this))

The following can be accessed using a deep link similar to the ones below where the parameters updated appropriately:

Booking:
https://karhoo.app/location?origin_latitude=51.49936&origin_longitude=-0.3142307&destination_latitude=51.51563&destination_longitude=-0.1744691&date_time=2020-06-27%2012:35

Trip tracking:
https://karhoo.app/triptracking?origin_display_address=Northfields%20Station,%20Northfield%20Ave,%20West%20Ealing,%20London%20W13%209QU,%20UK&destination_display_address=27%20London%20St,%20Paddington,%20London%20W2%201HH,%20UK&origin_latitude=51.49936&origin_longitude=-0.3142307&destination_latitude=51.51563&destination_longitude=-0.1744691&trip_id=eb699564-0a49-490a-9037-1a53b047bf58