Heads up! To view this whole video, sign in with your Courses Plus account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
In this video we'll learn how deep links work and start setting one up!
Related Links
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
[MUSIC]
0:00
Hi, this is Ben, and I'm here to tell you
a little bit about Deep Links and Android.
0:04
Deep links,
0:09
unlike regular links, are a way to link
a user to somewhere inside your app.
0:10
A good example of this
is the Wikipedia app.
0:14
If you search for something in Google,
for example, voxel and then
0:17
you click on the Wikipedia link provided
you have the Wikipedia app installed.
0:23
You get the option to open this link
right in Wikipedia and if we do that.
0:28
It doesn't just open to
the front page of Wikipedia,
0:35
it opens right to the voxel page.
0:38
This is a deep link.
0:40
Instead of just linking
us to the app itself
0:41
it linked us to the specific part of
the app that we're interested in.
0:44
Pretty cool right?
0:47
And actually they're
really easy to set up too.
0:49
It's just a few extra lines near
Android manifest to make your activity
0:51
receive the event.
0:55
And then you've just got to handle
the event in your activity.
0:56
So let's take a couple of minutes and
create an app that uses deep links.
0:59
The app we're going to make is
going to be a pretty simple one.
1:03
We're going to make it work with the
Treehouse tracks page and when the track
1:06
is selected the user will have the option
to open that link in our app, and
1:10
then our app will just display the name
of the track that was selected.
1:14
So first things first we're
going to need to create an app.
1:18
So let's choose start a new
android studio project and
1:21
then let's name it DeepLinks and
just accept all the defaults.
1:25
Now that we've got our app, let's modify
the manifest to let MainActivity receive
1:35
an intent whenever we click on
a link to one of the tracks.
1:40
To do this, we need to add a few entries
to the intent-filter for MainActivity.
1:44
The first thing we need
to add is another action.
1:50
But before we do that I'm going to take
out the space between the main action and
1:53
the launcher category.
1:57
And lets add a couple of lines at
the bottom to give us a little more room.
2:00
Specifically we need to
add the view action.
2:03
The view action is the most generic
action you can use on a piece of data.
2:06
And when a view action is encountered,
2:11
Android would do its best to show
that data and the right way.
2:13
For example clicking on a phone number
usually takes us to the dialer,
2:17
so let's add a new action element.
2:22
And for the name, let's use
2:25
android.intent.action.VIEW.
2:30
Nice, after a view action, we need
to add a couple of category entries.
2:36
The first category we need to
add is the default category.
2:41
If you want your activity to be
able to receive implicit intense,
2:44
then you need to declare
the default category.
2:48
An implicit intent is just any intent
where the target isn't directly specified.
2:51
So the intent that gave us the choice
of using the Wikipedia app or
2:56
the browser was an implicit intent.
3:00
Okay so let's add the default category,
3:03
category android name default.
3:08
And then the other category we need
to add is the browserable category.
3:11
Any activity that can be opened directly
from the browser must support this
3:16
category.
3:20
So category with android name of
BROWSABLE and then close the tag.
3:22
Also if you'd like to learn more
about the BROWSABLE category,
3:30
there's a helpful link below
in the teacher's notes.
3:33
Last but not least,
we need to add a data element.
3:36
The data element tells Android
which URL we're supporting.
3:39
So let's add a data element and then
inside we need to set three properties.
3:43
Since we want the app
to receive an intent,
3:50
whenever a user tries to navigate to one
of the tracks on the Treehouse website
3:52
we need to make this point to
the tree house tracks page.
3:57
To specify the tracks page,
we need to set the scheme, host, and
4:00
the path prefix properties.
4:04
So let's specify the scheme as HTTPS.
4:06
The host as teamtreehouse.com and
4:11
the path prefix as /tracks and
4:17
then let's close off our data tag.
4:23
All right we're all set up in
the manifest to start receiving
4:29
an intent whenever a user tries to
browse to the Treehouse tracks page.
4:34
Coming up we'll handle that intent and
see which track the user selected.
4:38
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up