3

Background

Android 7.1 now has a new feature called "AppShortcut" . On the docs, they explain how to create static ones and dynamic ones, and they even have a sample app.

The problem

I tried out the sample, yet I've noticed that when I click on the static app-shortcut, it shows me a toast "app isn't installed".

enter image description here

Looking at the code, I've found a suspicious configuration (in "shortcuts.xml" file) :

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android" >
    <shortcut
        android:shortcutId="add_website"
        android:icon="@drawable/add"
        android:shortcutShortLabel="@string/add_new_website_short"
        android:shortcutLongLabel="@string/add_new_website"
        >
        <intent
            android:action="com.example.android.appshortcuts.ADD_WEBSITE"
            android:targetPackage="com.example.android.appshortcuts"
            android:targetClass="com.example.android.appshortcuts.Main"
            />
    </shortcut>
</shortcuts>

It doesn't look good, because nothing in the app has this intent action of "ADD_WEBSITE" .

The dynamic shortcuts work fine btw (can be added via the normal launch of MainActivity).

What I tried

So I thought this should be changed. I tried to create a new activity and change this configuration to match the activity (action and targetCalss), but for some reason I still got the same toast .

The question

What could be wrong in the code? What should be changed to fix it?

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • Is anything of relevance showing up in LogCat? Note that in this case the relevant messages might be tied to system processes, not the app's process. – CommonsWare Oct 25 '16 at 14:13
  • The action string doesn't matter at all but it has to be present. https://commonsware.com/blog/2016/10/20/random-musings-7p1-developer-preview-1.html – Eugen Pechanec Oct 25 '16 at 15:37
  • The action being needed yet not being used for anything sounds like a bug. Have you reported about this (if so I will start it)? Do you know what is its purpose, that it looks this way? Have you found how to fix this issue? They also have "categories" tag. What is its purpose? I thought it's all similar to intent-filter. – android developer Oct 25 '16 at 20:15

2 Answers2

4

It's strange, but you can fix this by changing
android:targetPackage = "com.example.android.shortcutsample" (same as applicationid) or
applicationId "com.example.android.appshortcuts" (same as package name).

Sagar
  • 3,107
  • 2
  • 26
  • 35
quanlt
  • 834
  • 8
  • 6
  • Setting it to the applicationId of "com.example.android.shortcutsample" worked, but the targetPackage is already set to the package name of the app. It's exactly as I wrote, yet it didn't work. How come? And what's with the action and categories ? – android developer Oct 26 '16 at 07:06
0

Because your "com.example.android.appshortcuts.Main" don't has this action

com.example.android.appshortcuts.ADD_WEBSITE

You can change this action to

android.intent.action.VIEW
Trinea
  • 649
  • 8
  • 10