Sharing Shortcuts in Android
Last Updated :
08 Sep, 2021
With the release of Android Q and its amazing features, it also introduced Sharing Shortcuts. In Q, the Direct Share API has been superseded with the Sharing Shortcut API.
Receiving Data from Simple Ends
An app can not only transmit data to other applications, but it can also receive data from other apps. Consider how users interact with your app and what data types you wish to collect from other apps. For example, a social networking app may be interested in receiving text information from another app, such as an intriguing site URL. Sharing shortcuts, a quicker way to share material from your app, are introduced in Android Q. Think of it as direct share on steroids. This post will explain the distinction between the two and how to use sharing shortcuts.
Making Fabulous Share Targets?
Users will frequently provide data to your app via Android Sharesheet or the intent resolver. The MIME type of all received data is determined by the app that provides it. Your app can accept data supplied by another app in three ways:
- An Activity in the manifest with a matched intent-filter tag
- One or more ChooserTarget objects are returned by your app's ChooserTargetService Sharing Shortcuts.
- These take precedence over ChooserTarget objects.
- Sharing Shortcuts are only accessible if your app is running on Android 10 or higher (API level 29).
<activity android:name=".something.GeeksforGeeks" >
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>Aside from that, what exactly is a chooser service?
The share sheet is presented when a user, for example, wishes to share text information from an app. During the sheet preparation process, the system requests specific chooser services to get a list of chooser targets, which can be a regularly emailed contact on your device, a recently active group messaging discussion, or any other relevant item.
Technically, the chooser service is an Android service that is called by the system when a user expressly requests that another app choose a target for an intent, and it provides a list of chooser targets that deep link into the selected app.
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
When another app tries to share any of these items by creating intent and giving it to startActivity(), your app will be displayed as an option in the Android Sharesheet or intent resolver. If the user chooses your application, the associated activity (.ui.MyActivity in the preceding example) will be launched. It is then up to you to properly manage the material within your code and UI. The App Manifest should include the metadata required to operate with compatible libraries. Do this like:
<activity android:name=".GeeksforGeeks">
...
<meta-data android:name="gfg.sampleApp.gfgShorts"
android:resource="@xml/shortcuts"/>
</activity>Take care of the incoming stuff
To deal with the material given by an Intent, use getIntent() to obtain the Intent object. Once you've obtained the object, you can study its contents to figure out what to do next. Keep in mind that if this activity may be launched from other areas of the system, such as the launcher, you must account for this when analyzing the purpose.
GeekTip: When a shortcut is set to be long-lived, system services can continue to retrieve it from the cache even after it has been deleted as of a dynamic shortcut.
Now, to test, simply share a text, and then in the sample app, you will see the shortcuts pop-up!
Image 1. The sharing shortcuts
Similar Reads
Spotlight in Android
Android applications have so many options present within them, so users can interact with the features within the application. Many application provides a spotlight on some of the important features within the application to grab user attention. In this article, we will take a look at How to add Spo
4 min read
Settings Panels in Android
With the release of Android Q by Google, a slew of new features have emerged. Location Service use is one wonderful feature, among others. In this article, we will focus on three Settings choices in particular. Internet connectivity (particularly Wifi): It displays the settings panels for Mobile dat
3 min read
Synthetic Binding in Android
In android application development, for every view in the XML, we need to get an instance of that view to get access to it for doing any operation on it, like changing any property of a view. This is a very common requirement in any android application development cycle. There are main two ways of a
3 min read
What is Intent in Android?
In Android, it is quite usual for users to witness a jump from one application to another as a part of the whole process, for example, searching for a location on the browser and witnessing a direct jump into Google Maps or receiving payment links in Messages Application (SMS) and on clicking jumpin
4 min read
What is Uri.parse() in Android?
Uri stands for Uniform Resource Identifier. Uri is the sequence of the characters used to identify resources uniquely over the internet. In this article, we are going to see what is Uri.parse() method in Android. Step-by-Step Implementation Step 1: Create a New Project in Android Studio To create a
2 min read
Sub-Menu in Android
In android, Menu is an important part of the UI component which is used to provide some common functionality around the application. With the help of Menu, users can experience a smooth and consistent experience throughout the application. In order to use the Menu, we should define it in a separate
3 min read
Show PDF Using Intent in Android
Android is an open-source operating system, based on the Linux kernel and used in mobile devices like smartphones, tablets, etc. Further, it was developed for smartwatches and Android TV. Each of them has a specialized interface. Android has been one of the best-selling OS for smartphones. Android O
3 min read
Strikethrough Text in Android
In this article, we are going to implement the strike-through feature on our TextView using this method. This can be useful when we want to edit our content but also want users to see the previous content. Like on the Amazon app we all have seen that the prices are shown with strikethrough when ther
3 min read
Android Toast in Kotlin
A Toast is a short alert message shown on the Android screen for a short interval of time. Android Toast is a short popup notification which is used to display information when we perform any operation in our app. In this tutorial, we shall not just limit ourselves by creating a lame toast but also
3 min read
Processing and Parsing XML in Android
In this blog, we will learn about one of Android's most fascinating topics. Even most of us are unaware of it, despite the fact that it is one of the most essential ideas in Android development. But, before we get into our topic, take out your phones and count the number of apps you have on your sma
6 min read