如何为Android 7.1应用程序创建静态应用程序快捷方式?

3

https://developer.android.com/preview/shortcuts.html#static - Daniel
1个回答

4
  1. Create android project with target api level 25
  2. Create an xml named shortcuts.xml under res, inside xml directory and add following code in it: (to create static shortcuts)

    <shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
        <shortcut
        android:enabled="true"
        android:icon="@mipmap/ic_launcher"
        android:shortcutDisabledMessage="@string/static_shortcut_disabled_message"       
        android:shortcutId="static"
        android:shortcutLongLabel="@string/static_shortcut_long_label"
        android:shortcutShortLabel="@string/static_shortcut_short_label">
         <intent        
           android:action="android.intent.action.VIEW"
           android:targetClass="<Fully_Qualified_Activity_Name>"
           android:targetPackage="Package_Name_Of_Activity" /> 
        </shortcut>
    </shortcuts>
    

Manifest.xml 文件中,为您的活动添加以下元数据标记:

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

长按应用程序图标进行测试。


请注意,您在其中使用了 ,这应该是 " 吗? - jmattheis
如果针对不同的产品风味有不同的targetPackage,该怎么办? - Nitrodbz
如何捕捉快捷键点击? - Jemo Mgebrishvili

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