
Working with Android 7.1 App Shortcuts
Android 7.1 introduced a new feature called App Shortcuts. When you long press your app icon, it shows shortcuts to specific actions which can be launched, on supported launchers. For example, a dialer app can show shortcuts to your recently dialed numbers. A messaging app can show shortcuts to your recent conversations.

In this tutorial, we will create two Activities and add these activities as shortcuts.
Prerequisites
Make sure you have updated your Android SDK to 7.1 and Created a virtual device with Android 7.1 System Image.
creating project
Here I have created an Android Studio project with package com.lagahit.appshortcuts also Activity as MainActivity and layout as activity_main. Our main layout has a Button to launch Profile Activity.
Creating Profile Activity
To the left of Android Studio, you will find Project Explorer. Right Click on the app from the project explorer and select,New -> Activity -> Empty Activity
Here I have created new Activity as Profile Activity and layout as activity_profile.
It has Text View which displays ProfileActivity.
Creating Shortcuts XML
The shortcuts which to be displayed in the launcher should be defined in an XML file. Let’s create a new shortcuts.xml in res -> xmlIt has root
Each shortcut should define shortcutId, label, icon and Intent which it wishes to launch
shortcuts.xml
.
Adding Shortcuts to Manifest
Finally this shortcuts.xml should be referenced in manifest’s meta-data.AndroidManifest.xml
Screenshot
ENJOY
Comments
Post a Comment