2017-04-19 252 views
2

我不斷收到錯誤,當我試圖在快捷方式按預期實現從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> 
+0

在你的'shortcuts.xml',嘗試改變'機器人:行動= 「android.intent.action.VIEW」''到Android的:行動= 「android.intent.action.MAIN」' 。這樣,你匹配你的''。除此之外,是否還有更多的堆棧跟蹤,如一個或多個「由...引起」部分? – CommonsWare

+0

我覺得這行缺少您的代碼在shortcuts.xml文件中 –

+0

我試圖將action改爲action.VIEW,但似乎沒有做任何事情。 –

回答

0
<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> 
+0

據我所知,這並沒有做任何事情,分類名稱也不是強制性的。 –

+0

https://issuetracker.google.com/issues/37124563這可能有助於 –

1

崩潰日誌顯示包的名稱爲 「com.company.myapp.debug」。我認爲你的build.gradle在「productFlavors」部分包含applicationId +「.debug」。在這種情況下,您需要更改productFlavors或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> 
0
<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> 
相關問題