Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android app icon shorcut not launching activity

I'm trying to implement app icon shortcut on Android. I followed the documentation but I'm having problem launching the app from the shortcut. Every time I click the app icon shortcut, nothing happens. Here's the code on my AndroidManifest.xml file:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.package.myapp">

<application
    android:name=".MyApp"
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme.NoActionBar"
    android:usesCleartextTraffic="${usesCleartextTraffic}"
    tools:ignore="ExportedService,GoogleAppIndexingWarning,UnusedAttribute">

    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

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

    ...

</application>
</manifest>

Here's the shortcuts.xml file:

<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="UnusedAttribute">

    <shortcut
        android:enabled="true"
        android:icon="@drawable/ic_send"
        android:shortcutId="send_funds"
        android:shortcutLongLabel="@string/LBL_SEND_FUNDS"
        android:shortcutShortLabel="@string/BTN_SEND">

        <intent
            android:action="android.intent.action.VIEW"
            android:targetClass="com.package.myapp.MainActivity"
            android:targetPackage="com.package.myapp" />
    </shortcut>

</shortcuts>
like image 807
mgcaguioa Avatar asked Dec 30 '25 03:12

mgcaguioa


1 Answers

So the issue was on the buildType. When running on buildTypes other than the release build, I'm having the issue because the package name is different from what was indicated on the android:targetPackage of shortcut's intent. So what I did was, I created multiple shortcuts.xml with different targetPackage in the respective build folder:

app/src/debug/res/xml/shortcuts.xml
app/src/dev/res/xml/shortcuts.xml
app/src/staging/res/xml/shortcuts.xml

And set the android:targetPackage respectively:

android:targetPackage="com.package.myapp.debug"
android:targetPackage="com.package.myapp.dev"
android:targetPackage="com.package.myapp.staging"

Thanks to this SO question which is almost similar to my issue. And to Rakesh's answer.

like image 61
mgcaguioa Avatar answered Jan 01 '26 21:01

mgcaguioa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!