安卓应用快捷方式无法使用

6

我已经更新了Android Studio以支持API 25,并在项目中实现了它。我还寻找不同的资源来找到正确的答案,但没有成功。首先,我需要说的是,我在Android 6.0.1上测试应用程序,使用的是Action和Nova Launcher(但Google应用程序可以工作)。

所以,在AndroidManifest.xml中我实现了:

            <meta-data
            android:name="android.app.shortcuts"
            android:resource="@xml/shortcuts" />

xml - res中创建了shortcuts.xml,并输入以下内容:
<shortcut
    android:shortcutId="sc1"
    android:enabled="true"
    android:icon="@drawable/ic_kalendar"
    android:shortcutShortLabel="@string/shortcut_kalendar"
    android:shortcutLongLabel="@string/shortcut_kalendar_long"
    android:shortcutDisabledMessage="@string/message_off">
    <intent
        android:action="android.intent.action.MAIN"
        android:targetClass="com.ips.orto.MainActivity"
        android:targetPackage="com.ips.orto" />
    <intent
        android:action="android.intent.action.VIEW"
        android:targetPackage="com.ips.orto"
        android:targetClass="com.ips.orto.kalendar.Kalendar"/>
</shortcut>

<shortcut
    android:shortcutId="sc2"
    android:enabled="true"
    android:icon="@drawable/ic_else"
    android:shortcutShortLabel="@string/shortcut_else"
    android:shortcutLongLabel="@string/shortcut_else_long"
    android:shortcutDisabledMessage="@string/message_off">
    <intent
        android:action="android.intent.action.MAIN"
        android:targetClass="com.ips.orto.MainActivity"
        android:targetPackage="com.ips.orto" />
    <intent
        android:action="android.intent.action.VIEW"
        android:targetPackage="com.ips.orto"
        android:targetClass="com.ips.orto.else.Something"/>
</shortcut>

我尝试在属性中删除android:,但仍然无法正常工作。此外,我将android:exported="true"添加到指向Shortcuts中的Activity,并且我没有在任何特殊的v- bucket中创建shortcuts.xml。 有谁知道我做错了什么吗?


我建议您在Android 7.1上进行测试,例如使用模拟器。我没有尝试过Nova Launcher(如果我没记错的话,他们的应用程序快捷方式支持还处于测试版),但是Action Launcher目前肯定存在问题。在Pixel和7.1模拟器上工作的清单应用程序快捷方式在Action Launcher上无法正常工作。 - CommonsWare
2个回答

5

所以,我终于找到了答案。Catch非常简单。代码:

<activity ...>
<meta-data 
    android:name="android.app.shortcuts"     
    android:resource="@xml/shortcuts"/></activity>

需要在Mainfestapplication部分和shortcuts.xml中创建定义的Activity中添加meta,例如,如果您将快捷方式定义为ThirdActivity,则需要在Manifest中的该Activity中添加上述代码。此外,只有选择的活动需要此行:

android:exported="true"

之后在动作(Action)和Nova Launcher中,它可以正常工作,并且在Android 7.1模拟器中也可以。


这真的帮了我很多,完美的解决方案。 - Amrutha Saj
3
虽然该解决方案适用于您的情况,但重要的是要注意,<meta-data .../>必须位于其 intent-filters 设置为android.intent.action.MAIN操作和android.intent.category.LAUNCHER类别的活动内,正如文档中所述。 - Mariano Córdoba
看起来不再需要将其声明为<application>元素的子元素了(在版本7.0.57上进行了测试)。 - Mark

0

过时的链接! - Renjith

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接