javaandroidandroid-studiokotlinandroid-shortcut

static shortcut android don't appear


I try to add a shortcut to my application, but when I do a long click I don't see it.

I double checked my application id, also the activity.

Here is what I try.

My shortcut.xml :

  <shortcut
    android:shortcutId="conso"
    android:enabled="true"
    android:icon="@drawable/ic_budgeting"
    android:shortcutShortLabel="@string/shortcut_conso_short"
    android:shortcutLongLabel="@string/shortcut_conso_long"
    android:shortcutDisabledMessage="@string/shortcut_conso_dissable_message">
    <intent
        android:action="android.intent.action.VIEW"
        android:targetPackage="com.****.stubs_dev.debug"
        android:targetClass="com.******iviConsoActivity" />
    <!-- If your shortcut is associated with multiple intents, include them
         here. The last intent in the list determines what the user sees when
         they launch this shortcut. -->

</shortcut>

on manifest i add

on application and on activity i add also android:exported="true"

what's wrong with my code ?

EDIT here my manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="****">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" 
/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />



<application
    android:name="....."
    android:icon="@mipmap/..."
    android:label="@string/app_name"
    android:networkSecurityConfig="@xml/network_security_config"
    android:resizeableActivity="false"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    android:usesCleartextTraffic="true"
    tools:replace="icon">

....

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

My activity declaration :

   <activity
        android:name=".****onsoActivity"
        android:screenOrientation="portrait"
        android:exported="true"
        android:theme="@style/AppTheme.NoActionBar"
        >
        <meta-data android:name="android.app.shortcuts"
            android:resource="@xml/shortcuts" />
    </activity>

Solution

  • Make sure your xml name is shortcuts.xml then make sure you are adding shortcuts.xml to the launcher Activity that has the android.intent.action.MAIN and android.intent.category.LAUNCHER intent filters. Let's assume it is MainActivity then it would look like this

    <activity android:name=".MainActivity">
       <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" />