Saturday, March 18, 2017

Android - App Shortcuts, Android Nougat 7.1 Feature.

Android Nougat 7.1, the newest version of Android has come with several new features. Here I'm going to explain App Shortcuts. App Shortcuts allows the user to move on a specific screen from the app launcher. The feature is available on any launcher that supports them, such as YouTube app launchers, Android Nougat 7.1.

App Shortcuts, YouTube in Android Nougat 7.1

To reveal the shortcuts of an app, simply long-press the launcher icon of that app. Then tap on a shortcut to jump to the associated action. These shortcuts are a great way to engage users and provide some menu options of your app even before users launch your app.

Each shortcut references an intent, each of which launches a specific action or task, and you can create a shortcut for any action that you can express as an intent. For example, you can create intents for sending a new text message, making a reservation, playing a video, continuing a game, loading a map location, and much more.

Implement it we have two ways

 A) Statically  (by declaring all the shortcuts in a resource file, also known as manifest shortcuts).

 B) Dynamically (by adding the shortcuts at runtime).

Let's talk about the static approach.

1. Create a shortcuts.xml file and keep it on following location in the project.

 <shortcuts xmlns:android="">



As we can see each shortcut tag defines a series of attributes, like the icon and labels, and also references an intent which is set to launch a specific activity when triggered. Attributes android:shortcutId is a mandatory attribute. If it is not declared it will cause the respective shortcut not to appear in the shortcuts list. The recommended maximum number of shortcuts is 4, although it is possible to publish up to 5.

2. Reference shortcuts.xml file in the AndroidManifest.xml as metadata to the App’s launcher activity.
<activity android:name=".MainActivity">
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
           android:resource="@xml/shortcuts" />

Any activity that has the intent-filter action set to android.intent.action.MAIN and the category to android.intent.category.LAUNCHER can display app shortcuts.

Now run the project, the result might look something like this

Implementation of Dynamically Approach. 

For handle Static and Dynamic App shortcuts Nougat 7.1 provides us ShortcutManager. ShortcutManager is the entry point for manipulating (adding, updating, removing) shortcuts at runtime. 
private void createDynamicAppShortCut() {
       ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
        Intent intent = new Intent(this, DetailActivity.class);
        ShortcutInfo shortcut = new ShortcutInfo.Builder(this,                    getString(R.string.shortcut_label_new_task_dy))
                .setIcon(Icon.createWithResource(this, R.drawable.ic_launcher))

Trigger the above method at a runtime and move to App Launcher, You will see, we have one more shortcut.

ShortcutManager provides us with some interesting methods.

updateShortcuts (List ids) – update all existing shortcuts by ID.

removeDynamicShortcuts (List ids) – delete dynamic shortcuts by ID.

disableShortcuts (List ids) – disable dynamic shortcuts by ID.

reportShortcutUsed (String shortcutId) – You want to call this method whenever the user selects the shortcut containing the given ID or when the user completes an action in the application that is equivalent to selecting the shortcut. 

Something more

If you tap and drag a shortcut then it will be pinned to the device’s launcher:

When App Shortcuts disable or updated as used, Icon color will be changed. Something like this


Get it on Google Play

Flutter - Expendable list with ExpansionTile and ExpansionPanel

In mobile application, if you want to show items in a list with expandable feature. The expandable view is a way that show items in a vertic...