Android App Shortcuts使用

Shortcuts有两种实现方式

静态注册:在xml中定义, 适用于一些通用的动作.

动态注册: 由ShortcutManager发布, 可以根据用户的行为或者偏好添加, 可以动态更新.


1.静态使用,就是在xml中

xmlns:android="http://schemas.android.com/apk/res/android">

    
    
    
    
    
    
    
            android:shortcutId="settings"
        android:enabled="true"
        android:icon="@mipmap/ic_launcher"
        android:shortcutShortLabel="@string/short_name"
        android:shortcutLongLabel="@string/long_name"
        android:shortcutDisabledMessage="@string/cant_use_tag">
        
        
        
                    android:action="android.intent.action.VIEW"
            android:targetPackage="com.yihui.com.androidv"
            android:targetClass="com.yihui.com.androidv.CreatFileActivity" />
        
                    android:action="android.intent.action.VIEW"
            android:targetPackage="com.yihui.com.androidv"
            android:targetClass="com.yihui.com.androidv.TextTypeActivity" />

        android:name="android.shortcut.conversation"/>
    
    
            android:shortcutId="settings1"
        android:enabled="true"
        android:icon="@mipmap/ic_launcher"
        android:shortcutShortLabel="@string/short_name"
        android:shortcutLongLabel="@string/long_name"
        android:shortcutDisabledMessage="@string/cant_use_tag">
                    android:action="android.intent.action.VIEW"
            android:targetPackage="com.yihui.com.androidv"
            android:targetClass="com.yihui.com.androidv.StateLayoutActivity" />

        android:name="android.shortcut.conversation"/>
    

然后在要使用的的地方

Android App Shortcuts使用_第1张图片

2.动态注册

Android App Shortcuts使用_第2张图片

Android App Shortcuts使用_第3张图片

Shortcuts的总数不能超过5个, 即静态和动态shortcuts加起来总数最多是五个.
当我们尝试添加第六个shortcut时, 应用会抛出异常: java.lang.IllegalArgumentException: Max number of dynamic shortcuts exceeded.

你可能感兴趣的:(技术分析)