gpt4 book ai didi

Android 7.1 应用程序快捷方式 : Couldn't start activity

转载 作者:搜寻专家 更新时间:2023-11-01 08:27:22 24 4
gpt4 key购买 nike

当我尝试从 API 25 实现相当新的静态应用程序快捷方式时,我不断收到错误。

我制作了一个示例应用程序,其中的快捷方式按预期工作,但是当我尝试在我自己的应用程序中实现它们时,我不断收到以下错误:

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)

我认为问题与我的包结构有关。下面是我的 list 和快捷方式 xml。

list :

<?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>

快捷方式.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>

最佳答案

崩溃日志显示包名称为“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>

关于Android 7.1 应用程序快捷方式 : Couldn't start activity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43494350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com