Better share targets with Direct Share (Android Development Patterns S2 Ep 7)

Better share targets with Direct Share (Android Development Patterns S2 Ep 7)


When I go to share
something, it’s probably because I had a
fleeting thought about how cool it was, which
means that if it takes too long to actually share, I’m
going to hit the Back button and give up. I’m Joanna Smith, and I am
your least favorite user. To help you create magic
moments when sharing, Android Marshmallow
introduced a new feature called Direct Share. With Direct Share, you can
define direct share targets that launch a specific
activity in your app when the user initiates a share. To be clear here,
consider the current flow. If I found a fun new
article to show my sister, and I select your app
from the Share dialog, your app launches. That’s great. But a direct share means that
I can select my conversation with my sister,
and your app opens to that conversation with
the article already waiting in the message text
view for me to hit Send. Now that is a good
user experience. To enable direct
share targets, you must define a class that extends
from ChooserTargetService, and in this new
service of yours, you need to implement
onGetChooserTargets. This method is the one that
will offer up those share targets to the system so that it
may populate the Share dialog. OnGetChooserTargets is where
your app can get as fancy as its little heart desires. Maybe it makes the most
sense to offer up the 10 most recent conversations, or
perhaps your app offers a way for users to track who
they care the most about, and you can provide a list
of those BFFs instead. Or maybe you know
which conversations, like group messages,
for example, are most prone to
using attachments, and those are your
likely share targets. This magic is up to you. We just made the
framework so that you could build a better app. Now we need to
update our manifest. As with any new service,
we need to declare it, but what is special
about our declaration is the BIND_CHOOSER_TARGET_SERVICE
permission. This will let us
interact with the system to exchange those
implicit intents and share targets properly. Oh, and of course, the
intent filter that associates this service as a
chooser target service. That covers everything you need
to populate the system share dialog, but what about
when the user selects one of your options? You’ll want to start the proper
activity when your app is launched, and to
do that, you need to tie those specific activities
to the correct implicit intent. So you’ll need some
metadata to do this, but it really is
as simple as that. So to play with Direct
Share in your own app, take a look at our
super fun sample, which is linked in the
description below, or check out our documentation. But most importantly, just
continue to build better apps. [MUSIC PLAYING]

8 Comments on "Better share targets with Direct Share (Android Development Patterns S2 Ep 7)"


  1. What would be better is having a 2 stage share process.
    Even though the app I want "DOES" do direct share, because so many other apps do direct share too, the direct share I actually WANT to do is usually not there..

    What would be best, if give me a list of all the apps, then when I click on the app, give me the apps direct share list..
    You will then complain that I have just turned it into a 2 step process?? Well, I turned a 4 or 5 step process into a 2 step process. Since the direct share I want is not there, I have to click on the app anyway and then wait for it to load, then wait for it to give me the internal list, and then click who I want to share with.

    Reply

  2. How do you show the direct-share dialog itself? To
    Is it the normal sharing dialog?
    me it seems you show the opposite on the video. Am I correct?
    Also, is it possible to customize it?

    BTW, second link is dead (this : http://developer.android.com/about/ve/index.html )

    Reply

Leave a Reply

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