Android Shortcuts - App isn't installed error even though targetPackage and targetClass are correct
Asked Answered
P

1

4

I tried implementing the Android Shortcuts when holding the icons in the home screen. But when I try to launch them I get an

"App isn't installed" Toast

This is my shortcuts.xml:

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">

    <shortcut
        android:icon="@drawable/plus_black"
        android:shortcutId="add_sub"
        android:shortcutLongLabel="@string/shortcut_add_sub_long"
        android:shortcutShortLabel="@string/shortcut_add_sub">

        <intent
            android:action="android.intent.action.VIEW"
            android:targetClass="com.dancam.subscriptions.AddSubscription.AddSubscription"
            android:targetPackage="com.dancam.subscriptions.AddSubscription" />
    </shortcut>

    <shortcut
        android:icon="@drawable/pen"
        android:shortcutId="create_sub"
        android:shortcutLongLabel="@string/shortcut_create_sub_long"
        android:shortcutShortLabel="@string/shortcut_create_sub">

        <intent
            android:action="android.intent.action.VIEW"
            android:targetClass="com.dancam.subscriptions.CreateSubscription.CreateSubscription"
            android:targetPackage="com.dancam.subscriptions.CreateSubscription" />
    </shortcut>
</shortcuts>

I have already looked at this question but I couldn't find a suitable solution.

This is how my package/class tree looks like:

file tree

Any clue on how to fix this?

Picofarad answered 8/2, 2018 at 22:23 Comment(2)
Replace both android:targetPackage attribute values with your applicationId and see if that helps.Tank
@Tank Thanks this worked but why does it require the applicationId instead of the actual package as the name suggests?Picofarad
T
11

Replace both android:targetPackage attribute values with your applicationId.

Here, "package" refers to the applicationId (a.k.a., package name), not the Java package of the class.

Tank answered 8/2, 2018 at 22:34 Comment(5)
How to handle if there are multiple flavors? ${applicationId} doesn't seem to work.Angwantibo
@SrikarReddy: I do not know what "doesn't seem to work" means. You might want to ask a separate Stack Overflow question, where you provide a minimal reproducible example demonstrating your problem.Tank
I'm getting "App isn't installed" Toast when I use ${applicationId} as android:targetPackage="${applicationId}".Angwantibo
I've debug and release buildtypes. So the target package names should be android:targetPackage="com.company.app.debug” and for release builds it should be android:targetPackage=“com.company.app” but I can’t dynamically set the required targetPackage using android:targetPackage="${applicationId}”.Angwantibo
@SrikarReddy: Ah, I understand. ${applicationId} is a manifest feature, not for resources. So, have different versions of this shortcut XML in your debug/ and release/ source sets.Tank

© 2022 - 2024 — McMap. All rights reserved.