我不斷收到錯誤,當我試圖在快捷方式按預期實現從API 25的Android 7.1應用程序的快捷方式:無法啓動活動
我做出了示例應用程序的相當新的靜態應用的快捷方式,但當我試圖實現他們自己的應用程序我不斷收到以下錯誤:
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)
我認爲這個問題有事情做與我的包結構。 以下是我的清單和快捷方式xml。
清單:
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>
在你的'shortcuts.xml',嘗試改變'機器人:行動= 「android.intent.action.VIEW」''到Android的:行動= 「android.intent.action.MAIN」' 。這樣,你匹配你的''。除此之外,是否還有更多的堆棧跟蹤,如一個或多個「由...引起」部分? –
CommonsWare
我覺得這行缺少您的代碼 在shortcuts.xml文件中 –
我試圖將action改爲action.VIEW,但似乎沒有做任何事情。 –