App Shortcuts 功能描述
仅支持Android 7.1 (API level 25)及以上版本
Shortcut静态和动态的总和不能超过5个,但目前仅支持4个
一、静态注册:
1、创建resource文件res/xml/shortcuts.xml.
在<shortcuts>下可添加多个shortcut(shortcutId是唯一标识,相同shortcutId会被覆盖),
为shortcut添加<intent>(intent必须设置android:action属性)
2、 在AndroidManifest.xml中在已经设置好
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />的<activity>标签下添加
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
二、动态注册:
1、判断版本(Android 7.1 (API level 25)及以上)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
AddAppShortCuts();//动态添加的方法
}
2、动态添加
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "id1")
.setShortLabel("拖为独立窗口的title")
.setLongLabel(快捷列表中title")
//设置列表图标
.setIcon(Icon.createWithResource(context, R.drawable.icon_website))
//intent 必须设置action属性
(可跳到指定的acticity、网页)
.setIntent(new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.mysite.example.com/")))
[可两步跳转.setIntents(
new Intent[]{
new Intent(Intent.ACTION_MAIN, Uri.EMPTY, this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK),
new Intent(DynamicShortcutActivity.ACTION_OPEN_DYNAMIC)})]
.build();
shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
官网地址:https://developer.android.com/guide/topics/ui/shortcuts.html#dynamic
Demo学习地址:
http://www.cnblogs.com/mengdd/p/5996665.html ***博客园 (Demo下载地址:http://download.youkuaiyun.com/detail/xiaomengzi_16/9740814 )
http://blog.youkuaiyun.com/mqcluck/article/details/53586117 ***惜宇之梦博客
http://blog.youkuaiyun.com/ddwhan0123/article/details/53035677 王亟亟的博客
http://www.jianshu.com/p/b1ca41ee6e01 简书
http://www.360doc.com/content/16/1026/22/33279485_601619113.shtml 个人图书馆