繁体   English   中英

如何在Android 7.1上正确创建静态App-Shortcut?

[英]How to correctly create static App-Shortcut on Android 7.1 ?

背景

Android 7.1现在有一个名为“ AppShortcut ”的新功能。 在文档中,他们解释了如何创建静态的和动态的,他们甚至有一个示例应用程序

问题

我试用了这个示例,但是我注意到当我点击静态应用程序快捷方式时,它会向我显示“to app is not installed”。

在此输入图像描述

看一下代码,我发现了一个可疑的配置(在“shortcuts.xml”文件中):

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android" >
    <shortcut
        android:shortcutId="add_website"
        android:icon="@drawable/add"
        android:shortcutShortLabel="@string/add_new_website_short"
        android:shortcutLongLabel="@string/add_new_website"
        >
        <intent
            android:action="com.example.android.appshortcuts.ADD_WEBSITE"
            android:targetPackage="com.example.android.appshortcuts"
            android:targetClass="com.example.android.appshortcuts.Main"
            />
    </shortcut>
</shortcuts>

它看起来不太好,因为应用程序中没有任何内容具有“ADD_WEBSITE”的意图操作。

动态快捷方式工作正常btw(可以通过MainActivity的正常启动添加)。

我尝试了什么

所以我认为应该改变。 我尝试创建一个新活动并更改此配置以匹配活动(action和targetCalss),但由于某种原因,我仍然得到相同的toast。

这个问题

代码中可能有什么问题? 应该修改什么来修复它?

这很奇怪,但你可以通过改变来解决这个问题
android:targetPackage = "com.example.android.shortcutsample" (与applicationid相同)或
applicationId "com.example.android.appshortcuts" (与包名相同)。

因为你的“com.example.android.appshortcuts.Main”没有这个动作

com.example.android.appshortcuts.ADD_WEBSITE

您可以将此操作更改为

android.intent.action.VIEW

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM