Create shortcuts android App | Show Menu Long press on App icon – Kotlin

Have you seen the android app options menu on press any application? Android shortcuts menu deliver specific types of content to your users. In this tutorial, you will learn how to Create shortcuts android App in different ways.

Create shortcuts android App Show Menu Long press App icon

In this tutorial, you will learn the following:

  • App shortcuts overview
  • Shortcut types
  • Create shortcuts

App shortcuts overview

Shortcuts are used in-app for a purpose to your users by helping them quickly access parts of your app. Like a youtube app has an option on long-press icon show three-option menu “Trending”, “subscriptions” and “search”. By clicking on the option you can directly access these features.

Android App Shortcut types

  1. Static shortcuts:- Context doesn’t change
  2. Dynamic Shortcuts:- Context constantly changes
  3. Pinned Shortcuts:- Context is defined by the user

Let’s Build a Simple Android App Shortcut on Long press :

In the example, we will cover Static and Dynamic shortcuts. When a user do Long click on the application icon it will popup a menu with app options.

Step 1. Create a new project “Build Your First Android App in Kotlin

Step 2. Open the “MainActivity.kt” and add the following code.

We added a dynamic shortcut code in the activity.

Step 3. Add the following string in the strings file. (res/values/strings.xml)

Step 3. Create a shortcuts.xml file and add the following code.

Now we are creating static shortcuts. You need to create shortcuts file at “res/xml/shortcuts.xml“, if XML directory not there, then create it.

See the below screenshot for better help.

Create static and dynamic shortcuts android App

Add the following code in “shortcuts.xml”.

Step 4. Now Run the application, in an emulator or on your Android device.

Output screenshot Android Shortcuts app example :

Create shortcuts android App  output

Download source code Android Shortcuts in kotlin

https://github.com/EyeHunts/AndroidAppShortcuts

How to display menu options after Long press on an Android app icon like Paytm and Swiggy?

Answer: It can be your interview question. You can do it using shortcuts.

Do comment if you have any doubts and suggestions on this tutorial.

Note: This example (Project) is developed in Android Studio 3.3.2. Tested on Android 9 ( Android-P), compile SDK version API 28: Android 9.0 (Pie)
MinSdkVersion=”25″
TargetSdkVersion=”28″
Coding in Kotlin


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.