Search code examples
android-7.1-nougat

How to create static app shortcut for android 7.1 app?


like this I want to do with my own shortcuts. And to open particular activity depending on shortcut type

https://i.sstatic.net/Q87SO.png


Solution

    1. Create android project with target api level 25
    2. Create an xml named shortcuts.xml under res, inside xml directory and add following code in it: (to create static shortcuts)

      <shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
          <shortcut
          android:enabled="true"
          android:icon="@mipmap/ic_launcher"
          android:shortcutDisabledMessage="@string/static_shortcut_disabled_message"       
          android:shortcutId="static"
          android:shortcutLongLabel="@string/static_shortcut_long_label"
          android:shortcutShortLabel="@string/static_shortcut_short_label">
           <intent        
             android:action="android.intent.action.VIEW"
             android:targetClass="<Fully_Qualified_Activity_Name>"
             android:targetPackage="Package_Name_Of_Activity" /> 
          </shortcut>
      </shortcuts>
      

    Inside Manifest.xml add this meta-data tag for your activity:

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

    And test it by long pressing app icon.