Updated 6 September 2017
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.
1 2 3 |
// App Shortcuts compile 'com.github.matthiasrobbers:shortbread:1.0.1' annotationProcessor 'com.github.matthiasrobbers:shortbread-compiler:1.0.1' |
And to display the shortcuts, call Shortbread.create(Context context) in your Application class.
1 2 3 4 5 6 7 |
public class YourApplication extends Application { @Override public void onCreate() { super.onCreate(); Shortbread.create(this); } } |
Now all you need to do is add the annotations on your activity to start it from the app shortcut.
1 2 3 4 |
@Shortcut(id = "id", icon = R.drawable.your_drawable, shortLabelRes = R.string.your_lable_string, rank = 1, backStack = {YourBackstackActivity.class}) public class YourActivity extends AppCompatActivity { } |
As we can see in the above code segment, we have just added an annotation @Shortcut and assigned some attributes like
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.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.