GithubHelp home page GithubHelp logo

android-sharingshortcuts's Introduction

Android SharingShortcuts Sample

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

Introduction

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.

Direct Share was first introduced in Android M where you had to implement a service to provide direct share targets on demand. The way to do that changed in Android Q, you need to provide your direct share targets in advance. First, you have to declare share-target elements in the same application's resource file than static shortcuts. Then, you need to publish dynamic shortcuts with the same category you declared in the share-target with the ShortcutManager API. You will need to manually update the list of shortcuts every time you consider it appropriate. The API offers methods to update, remove or add shortcuts. You can use the ShortcutInfoCompat.Builder to customize your shortcut. If you don't want to block the UI thread doing these operations, interactions with the ShortcutManager can also happen on a background thread.

There are three ways the app is sending/receiving intents:

  • Dynamic Share: The user selected the app in the sharesheet to receive the text. After this, the user will have to select the contact to share the text with. In our case, the app receives an intent of type Intent.ACTION_SEND.
  • Direct Share: The user selected a person of your app in the sharesheet to share the text with. The received intent of type Intent.ACTION_SEND will contain a String EXTRA_SHORTCUT_ID that will have the id of the shortcut that was selected. After this, the app is ready to send the text.
  • Launcher shortcut: When the user taps on a launcher shortcut, the intent that was added to the shortcut will get fired. In our case, it triggers an intent of type Intent.ACTION_DEFAULT.

To make Direct Share backwards compatible with older Android versions, you need to add the AndroidX sharetarget library and 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 android:value as androidx.sharetarget.ChooserTargetServiceCompat.

Pre-requisites

  • Android SDK android-Q
  • Android Support Repository

Screenshots

Screenshot 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.

Support

If you've found an error in this sample, please file an issue: https://github.com/googlesamples/android-SharingShortcuts

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

License

Copyright 2019 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

http://www.apache.org/licenses/LICENSE-2.0

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.

android-sharingshortcuts's People

Contributors

google-automerger avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.