December 19, 2016
With Android 7.1 Nougat, Google has introduced a feature called app shortcuts that will seem familiar to fans of Windows phone and the iPhone. But this feature goes well beyond similar functionality on other mobile platforms.
In any event, Google is finally introducing its app shortcuts feature, tying together two major functional advantages of competing mobile platforms and, in doing so, creating something that is both unique and superior.
In Windows Phone 7 “Mango,” Microsoft introduced a platform feature called deep linking, which allowed apps to create secondary tiles that users could put on their Start screens to access specific functionality. Similarly, iOS introduced a function called 3D touch in iOS9. 3D Touch lets the user press and hold on an app icon on the Home screen and display a context menu of options.
Android 7.1’s app shortcuts work like 3D Touch in iOS in that you can now press and hold on compatible app icons to display a context menu of app shortcuts. But they also improve on that idea by incorporating the deep linking functionality from Windows phone. That is, you can drag any app shortcut in an app context menu to the home screen and create a new shortcut icon, a new entry point, for that app.
The App shortcuts feature also doesn’t require haptic hardware or a newer phone because Google doesn’t treat its users like ATM machines. You just press and hold on an icon and it works. (Assuming that the app supports this feature.)
Why to Support App Shortcuts?
Nowadays people can’t live without mobile phones but food. Mobile users would be interested in shortcuts as it would save their time.
Examples of actions you can express as shortcuts include the following:
Static shortcuts should provide links to generic actions within your app, and these actions should remain consistent over the lifetime of your app’s current version.
How to implement Static Shortcuts?
In your app’s manifest file (AndroidManifest.xml), find an activity whose intent filters are set to the android.intent.action.MAIN action and the android.intent.category.LAUNCHER category.
<manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.myapplication”>
<application … >
<intent-filter><action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.LAUNCHER” />
<meta-data android:name=”android.app.shortcuts” android:resource=”@xml/shortcuts” />
In this new resource file, add a <shortcuts> root element, which contains a list of <shortcut> elements. Each <shortcut> element, in turn, contains information about a static shortcut, including its icon, its description labels, and the intents that it launches within the app:
<categories android:name=”android.shortcut.conversation” />
Dynamic shortcuts should provide links to specific, context-sensitive actions within your app. These actions can change between uses of your app, and they can change even while your app is running.
How to implement Dynamic Shortcuts?
The ShorcutManger API allows you to complete the following operations on dynamic shortcuts:
Publish: Use setDynamicShortcuts() to redefine the entire list of dynamic shortcuts, or use addDynamicShortcuts() to augment an existing list of dynamic shortcuts.
Update: Use the updateShortcuts() method.
Remove: Remove a set of dynamic shortcuts using removeDynamicShortcuts(), or remove all dynamic shortcuts using removeAllDynamicShortcuts().
An example of creating a dynamic shortcut and associating it with your app appears in the following code snippet:
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, “id1”)
.setLongLabel(“Open the web site”)
We can also have more features in implementaion like, Tracking Shortcut usage, Disabling shortcuts, Assigning multiple intents, Rate limiting and Backup and restore.
I just wish more people could experience this feature.
Click the image below to download your free eBook.