3

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?

Daniele
  • 4,163
  • 7
  • 44
  • 95
  • Replace both `android:targetPackage` attribute values with your `applicationId` and see if that helps. – CommonsWare Feb 08 '18 at 22:26
  • @CommonsWare Thanks this worked but why does it require the `applicationId` instead of the actual package as the name suggests? – Daniele Feb 08 '18 at 22:31

1 Answers1

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 1
    How to handle if there are multiple flavors? `${applicationId}` doesn't seem to work. – Srikar Reddy Apr 23 '18 at 08:11
  • @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 [mcve] demonstrating your problem. – CommonsWare Apr 23 '18 at 09:57
  • I'm getting "App isn't installed" Toast when I use `${applicationId}` as `android:targetPackage="${applicationId}"`. – Srikar Reddy Apr 23 '18 at 10:06
  • 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}”`. – Srikar Reddy Apr 23 '18 at 10:06
  • 4
    @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. – CommonsWare Apr 23 '18 at 10:07