Android 7.1 – App Shortcuts

bhaskar

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:

  • Navigating users to a particular location in a mapping app.
  • Sending messages to a friend in a communication app.
  • Playing the next episode of a TV show in a media app.
  • Loading the last save point in a gaming app.

Static Shortcuts:

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.

  1. Add a <meta-data> element to this activity that references the resource file where the app’s shortcuts are defined:

<manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.myapplication”>

<application … >

<activity android:name=”Main”>

<intent-filter><action android:name=”android.intent.action.MAIN” />

<category android:name=”android.intent.category.LAUNCHER” />

</intent-filter>

<meta-data android:name=”android.app.shortcuts” android:resource=”@xml/shortcuts” />

</activity>

</application>

</manifest>

  1. Create a new resource file: res/xml/shortcuts.xml.

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:

<shortcuts xmlns:android=”http://schemas.android.com/apk/res/android”>

<shortcut

android:shortcutId=”compose”

android:enabled=”true”

android:icon=”@drawable/compose_icon”

android:shortcutShortLabel=”@string/compose_shortcut_short_label1″

android:shortcutLongLabel=”@string/compose_shortcut_long_label1″

android:shortcutDisabledMessage=”@string/compose_disabled_message1″>

<intent

android:action=”android.intent.action.VIEW”

android:targetPackage=”com.example.myapplication”

android:targetClass=”com.example.myapplication.ComposeActivity” />

<categories android:name=”android.shortcut.conversation” />

</shortcut>

</shortcuts>
Dynamic Shortcuts:

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”)

.setShortLabel(“Web site”)

.setLongLabel(“Open the web site”)

.setIcon(Icon.createWithResource(context, R.drawable.icon_website))

.setIntent(new Intent(Intent.ACTION_VIEW,

Uri.parse(“https://www.mysite.example.com/”)))

.build();

shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));

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.

Quick Guide to Planning Your Mobile Strateg

about the author

bhaskar