Courtesy: GitHub

Android DirectShare Sample

Sample demonstrating how to show some options directly in the list of share intent candidates.


Direct Share is a feature that allows apps to show their internal options directly in the system Intent chooser dialog. This sample is a dummy messaging app, and just like any other messaging apps, it receives intents for sharing a plain text. When a user shares some text from some other app, this sample app will be listed as an option. Using the Direct Share feature, this app also shows some of contacts directly in the chooser dialog.

To enable Direct Share, apps need to implement a Service extending ChooserTargetService. Override the method onGetChooserTargets and return a list of Direct Share options.

In your AndroidManifest.xml, add a meta-data tag in your Activity that receives the Intent. Specify android:name as android.service.chooser.chooser_target_service, and point the android:value to the Service.


  • Android SDK 26
  • Android Build Tools v26.0.1
  • Android Support Repository


Screenshot Screenshot Screenshot

Getting Started

This sample uses the Gradle build system. To build this project, use the "gradlew build" command or use "Import Project" in Android Studio.


If you've found an error in this sample, please file an issue:

Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub. Please see for more details.


Copyright 2017 The Android Open Source Project, Inc.

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

compile ""

compile ""

compile ""

compile ""

compileSdkVersion 26

minSdkVersion 23

targetSdkVersion 26


versionCode 1

versionName 1.0


Provides the landing screen of this sample. There is nothing particularly interesting here. All the codes related to the Direct Share feature are in {@link SampleChooserTargetService}.

Emits a sample share {@link Intent}.


Provides the UI for sharing a text with a {@link Contact}.

The request code for {@link SelectContactActivity}. This is used when the user doesn't select any of Direct Share icons.

The text to share.

The ID of the contact to share the text with.

Resolves the passed {@link Intent}. This method can only resolve intents for sharing a plain text. {@link #mBody} and {@link #mContactId} are modified accordingly. * @param intent The {@link Intent}. @return True if the {@code intent} is resolved properly.

Sets up the UI.

Delegates selection of a {@Contact} to {@link SelectContactActivity}.

Pretends to send the text to the contact. This only shows a dummy message.


The dialog for selecting a contact to share the text with. This dialog is shown when the user taps on this sample's icon rather than any of the Direct Share contacts.

The action string for Intents.


Provides the Direct Share items to the system.