Read More

Adding app shortcuts in your app

If you are looking for a feature just like iPhone’s 3D Touch than in the language of android we call it App Shortcuts. Introduced in Android Nougat (API Level 25), whenever you tap and hold on to any app icon then it displays some options which can directly take you to some activity. App shortcuts are only supported in Nougat and above.

They are of three types :

To achieve this feature you can go to Android Developer they have provided details steps to add shortcuts in the app. But adding shortcuts is little tricky some of the beginners may find it hard. We will be discussing the easy way of adding them.

Matthias Robbers have provided a library called Shortbread which provides a very easy way to implement app shortcuts. Let’s get started with this awesome library.

First, You need to add the two dependencies in your build.gradle.

 

And to display the shortcuts, call Shortbread.create(Context context) in your Application class.

 

Now all you need to do is add the annotations on your activity to start it from the app shortcut.

As we can see in the above code segment, we have just added an annotation @Shortcut and assigned some attributes like

  1. id – Give an id to the attribute
  2. icon – Icon that will be displayed.
  3. shortLabelRes – To provide a short label from a resource you can use shortLabel to provide a string.
  4. rank – It will decide the position of the shortcut.
  5. backstack – if you don’t add any activity in the backstack then when you directly open a particular activity on back press the application will get closed. In this case, YourBackstackActivity will be called first so that when you press the back button instead of closing the app YourBackstackActivity will be called.

That’s all!!! try adding the shortcuts in your app and you can definitely play with the other attribute of the library to get more awesome results.

The results will look somthing like this

Thank you very much. This is Vedesh Kumar signing off.

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close