安卓应用快捷方式不起作用



我更新了AndroidStudio以支持API 25并在项目中实现它。我也在寻找不同的资源来找到我问题的正确答案,但并没有运气。首先,我需要说的是,我用Action和Nova Launcher在Android 6.0.1上测试应用程序(但谷歌应用程序可以工作(。所以,我在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:,但仍然不起作用。此外,我添加了指向Shortcutsandroid:exported="true"Activity,并且我没有在任何特殊的v-bucket中创建shortcuts.xml。有人知道我做错了什么吗?

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

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

意味着不仅要在Mainfestapplication部分中添加meta,还要在shortcuts.xml中为其创建定义的Activity中添加(例如,如果您定义了ThirdActivity的快捷方式,则会在Manifest中将上述代码添加到该Activity(。此外,刚刚选择的活动需要这条线:

android:exported="true"

之后,它在Action和Nova Launcher以及Android 7.1模拟器中都可以正常工作。

shortcuts.xml文件必须在此处,res/xml-v25/shortcuts.xmlhttp://sunilkmrnishad.blogspot.in/2017/03/app-shortcuts-android-nougat-71-feature.html

最新更新