Reputation: 31
I keep getting errors when I am trying to implement the fairly new static app shortcuts from API 25.
I made an example app where the shortcuts are working as expected but when I try to implement them in my own app I keep getting the following error:
04-19 12:41:06.846 1623-2104/system_process E/LauncherAppsService: Couldn't start activity, code=-2 04-19 12:41:06.850 2090-2090/com.google.android.apps.nexuslauncher E/Launcher: Unable to launch. tag=DeepShortcutsContainer$UnbadgedShortcutInfo(id=-1 type=6 container=-1 screen=-1 cellX=-1 cellY=-1 spanX=1 spanY=1 minSpanX=1 minSpanY=1 rank=0 user=UserHandle{0} title=Declaratie) intent=Intent { act=android.intent.action.MAIN cat=[com.android.launcher3.DEEP_SHORTCUT] flg=0x10200000 pkg=com.company.myapp.debug cmp=com.company.myapp.debug/com.company.myapp.controllers.activity.LoginActivity bnds=[477,516][1023,642] (has extras) } android.content.ActivityNotFoundException: Shortcut could not be started at android.content.pm.LauncherApps.startShortcut(LauncherApps.java:751) at android.content.pm.LauncherApps.startShortcut(LauncherApps.java:717) at com.android.launcher3.shortcuts.DeepShortcutManager.startShortcut(SourceFile:142) at com.android.launcher3.Launcher.startShortcutIntentSafely(SourceFile:2752) at com.android.launcher3.Launcher.startActivitySafely(SourceFile:2841) at com.android.launcher3.Launcher.startAppShortcutOrInfoActivity(SourceFile:2594) at com.android.launcher3.Launcher.onClickAppShortcut(SourceFile:2585) at com.android.launcher3.Launcher.onClick(SourceFile:2406) at android.view.View.performClick(View.java:5637) at com.android.launcher3.shortcuts.DeepShortcutTextView.performClick(SourceFile:81) at android.view.View$PerformClick.run(View.java:22429) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
I think that the problem has something to do with my package structure. Below is my manifest and shortcuts xml.
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.company.myapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:name=".ApplicationEx"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".controllers.activity.LoginActivity"
android:screenOrientation="portrait">
<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"/>
</activity>
<activity
android:name=".controllers.activity.DashboardActivity"
android:screenOrientation="portrait" />
<activity
android:name=".controllers.activity.DeclarationActivity"
android:screenOrientation="portrait" />
<activity
android:name=".controllers.activity.CapturePickPhotoActivity"
android:screenOrientation="portrait" />
<activity
android:name=".controllers.activity.ProfileActivity"
android:screenOrientation="portrait" />
</application>
</manifest>
shortcuts.xml :
<shortcuts
xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="declaration"
android:enabled="true"
android:icon="@drawable/ic_add"
android:shortcutShortLabel="@string/shortcut_short_label_declaration"
android:shortcutLongLabel="@string/shortcut_long_label_declaration"
android:shortcutDisabledMessage="@string/shortcut_disabled_message">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.company.myapp"
android:targetClass="com.company.myapp.controllers.activity.LoginActivity" />
<!-- 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>
<!-- Specify more shortcuts here. -->
</shortcuts>
Upvotes: 2
Views: 2565
Reputation: 4069
<activity
android:name="com.***.Splash"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.NoActionBar">
<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" />
<intent-filter>
<action android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
Upvotes: 0
Reputation: 51
Crash log shows package name as "com.company.myapp.debug". I think your build.gradle contains applicationId + ".debug" in "productFlavors" section. In this case, you need to change productFlavors or shortcuts.xml.
<shortcuts
xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="declaration"
android:enabled="true"
android:icon="@drawable/ic_add"
android:shortcutShortLabel="@string/shortcut_short_label_declaration"
android:shortcutLongLabel="@string/shortcut_long_label_declaration"
android:shortcutDisabledMessage="@string/shortcut_disabled_message">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.company.myapp.debug"
android:targetClass="com.company.myapp.controllers.activity.LoginActivity" />
<!-- 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>
<!-- Specify more shortcuts here. -->
</shortcuts>
Upvotes: 3
Reputation: 381
<shortcuts
xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="declaration"
android:enabled="true"
android:icon="@drawable/ic_add"
android:shortcutShortLabel="@string/shortcut_short_label_declaration"
android:shortcutLongLabel="@string/shortcut_long_label_declaration"
android:shortcutDisabledMessage="@string/shortcut_disabled_message">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.company.myapp"
android:targetClass="com.company.myapp.controllers.activity.LoginActivity" />
<!-- 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. -->
<categories android:name="android.shortcut.conversation" />
</shortcut>
<!-- Specify more shortcuts here. -->
</shortcuts>
Upvotes: 0