App Links Assistant in Android Studio 2.3 – Android Tool Time

App Links Assistant in Android Studio 2.3 – Android Tool Time


SPEAKER: Adding support
for a new platform feature in your app can be
a very repetitive process. Many times you will
switch back and forth between your code and a step by
step tutorial or documentation, especially where you’re
not familiar with the API. That was the case when I
was implementing support for App Links, in a sample
app back when Android Marshmallow was released. App Links is a neat
feature that lets you verify a domain that is
listed in your activities content filters. From that moment
forward, whenever a user clicks on a URL
containing this domain, your app will open
automatically without showing the disambiguation dialog. I remember that in order
to make this API work, I had to make many small changes
in different parts of my app, which is why I was very curious
when I heard about the new App Links assistant that is part of
the Android Studio 2.3 release. Its promise– to add App
Links support in your project with just a few clicks
without leaving the IDE. Let’s see how that works out. I found the perfect sample
app for my experiment under Google/searchsamples
on Github. It’s a very bare
bones recipe app. The main page doesn’t
really do anything, but there is also a content
provider with several example recipes set up and ready to be
displayed in the detail page, implemented in recipe activity. All I need to do is
open the activity and call Show Recipe,
passing it content URI which matches a recipe
in the content provider. Now, imagine that I’m also
running a website for my app, and I’d like my users to
be able to share and open links to recipes in the same
way, regardless of which device they are using. Let’s see how long it takes to
implement this using the App Links assistant. You’ll find the assistant
under the Tools menu, and it shows up as a panel
on the right side here. First step, I want to define
URL mappings in my app. I will add just one to connect
recipe URLs to the detail activity. I just have to fill in my
website’s host name, and what path to match. I’ll use the path prefix recipe
to also capture any recipe ID after the last path separator. And I want to launch
the recipe activity. The tool generates the
correct intent filter, and adds it to my manifest. I can even see a
preview of the changes and check that the URL
I need will get matched to the correct activity. Step 2, add logic to the
activity to handle the URL. I’ll select the activity that I
specified in the previous step, and some code gets added
to my uncreate method. This is just to help you get the
necessary data from the intent. But remember that it’s up
to you to actually handle it in your app. In my case, I want to load
and show the correct recipe. For that, I need the recipe
ID, which is the last path part in the URL. Now I’ll just convert that to
a URI, pointing to my content provider, and pass
it on to Show Recipe. In some cases, such as this
one, when the activity’s launch mode is set to single
top, you will also have to handle a
new intent delivered to an already running
instance of the activity. I will refactor the code I
just wrote into a new method and code that from our
new intent as well. Before I move on to configuring
App Links on my server, I just want to check that
everything I configured so far works on the device. I’ll just use the App
Links tester in step 4 to launch a URL pointing to the
grilled potato salad recipe. It correctly launches my
app, and shows the recipe. Great. You might have
noticed that there’s a migration dialog that popped
up when I launch the URL. Getting rid of it and
launching directly into the app is the last part. Let’s proceed with step 3,
generating the digital asset links file. You’ll need a few
details about your app, such as the domain you’re using
in your links, application ID, and the signing config. Most of these will normally
be pre-filled for you so you can just click
the Generate button. Now, you will need to place
this file under this path on the domain that you control. Please note that
this is where it’s the easiest to make a mistake. The path must match exactly. The well-known folder must be
under the root of the domain, and the server must be using
a valid HTTPS certificate to serve the file even if your
App Links are only using HTTP. For testing my app, I’m
just using Github pages, which gives me an easy way of
hosting my asset links file with the correct
SSL certificate. Let’s test the sample
link again in step 4. And the app launches, taking
me directly into the recipe. No need to click through
a dialog this time. That’s App Links, fully added
to a sample app in just four steps, without looking
at the documentation. If you like the App
Links assistant, or if you have any
feedback, please let us know on our social channels. Thanks for watching, and for
more Android studio videos, click here.

28 Replies to “App Links Assistant in Android Studio 2.3 – Android Tool Time”

  1. Does the App Links Assistant also give you some pre-generated javascript code that you can add to your url link for redirecting to the play store if the app is not installed on your phone? That would be pretty neat.

  2. Very nice video! I didn't understand what app links were or how to implement it before this video. Now I know. Thanks 🙂

  3. What step 3 does? I mean what is the difference with and without assertlinks.json on website?

  4. Is it taken into consideration even when the app is not installed? Can a website's URL which is associated with an app redirect the user to the Play Store in this case?

  5. But what if the user actually doesn't want a specific app to be opened on a link, and instead, open the web-browser?

    Also, why is it needed to put a file on a server ?

  6. Assistant keeps failing with "Digital Asset Links file not found at {URL}" even though the file is uploaded (clicking the link there works fine), the format matches perfectly, URL encrypted with valid SSL certificate headers and Content-Type header is "application/json". The assistant should show what part of it is failing exactly. Have no idea how to get this working.

  7. Hi Android Developer.
    i am creating voice to text app and i ma using google API for this and it work but i want keep MIC on.
    can i MIC on for 5 minutes continuously??
    or
    can i MIC on till the application is On.
    please guide me about this scenario
    thanks

  8. Hello All I have a mac iOS version 10.13, now Android Studio supports upto 10.12, I cannot do Android Apps any more, I am dead in the water till Android/google finds an update. The HAXM wont install.

  9. Is there a way to check that app is installed or not. If app is not installed , navigate to play store. Please let me know if it's possible.

  10. Thanks for the tool, & great brief to the point video. Thanks for making our development easier 🙂

  11. how about using pathPattern? i think i must use it instead of pathprefix, because my wordpress website url use permalink in the first path of url, so there is no prefix path, its directly permalink after domain.
    but i cant found any documentation that describe about to use pathpattern. I got stuck. somebody can help me? please I would very thankful for that.

  12. very nice video. i have created same repositroty over github. i am able to access other pages but .well-known is not able to access from github. can you please elp me how to make .well-known folder on github.

  13. Is it worth it to do all this to just avoid the chooser dialog. Why not use Deep Linking with the app scheme to open an activity directly? Also, Android studio 3.2+ no longer has the tool App Link Assistant. How to get it?

Leave a Reply

Your email address will not be published. Required fields are marked *