shortcuts实现
来源:互联网 发布:mac whirl亚洲人试色 编辑:程序博客网 时间:2024/06/05 16:37
1.使用条件
android 7.1以上
2.功能说明
长按桌面app图标出现快捷方式列表,点击可跳转到app的指定界面,用户也可以将其作为一个单独的快捷方式
3.效果截图
3.技术实现
分为两种方式,静态xml配置和动态代码配置,二者各有优劣,xml配置不需要运行app就有了,但是快捷方式不可以取消。动态代码配置更灵活,可以在任意界面新增或者取消快捷方式
静态xml实现方式:新建xml资源文件,将需要内置的快捷方式写入<shortcuts>标签内,其中包括快捷方式的图标、名称、跳转的url等
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="yydb"
android:enabled="true"
android:icon="@drawable/fanli"
android:shortcutShortLabel="@string/yydb"
android:shortcutLongLabel="@string/yydb"
android:shortcutDisabledMessage="@string/yydb">
<intent
android:action="android.intent.action.VIEW"
android:data="需要跳转的url"
android:targetPackage="com.fanli.android.apps"
android:targetClass="com.fanli.android.basicarc.ui.activity.CustomUrlBridgeActivity" />
<categories android:name="android.shortcut.conversation"/>
</shortcut>
</shortcuts>
动态代码实现方式:需要先初始化shortcutinfo,给定快捷方式的属性,然后再调用setDynamicShortcuts告知系统改变快捷方式
ShortcutManager scManager = getSystemService(ShortcutManager.class);
ShortcutInfo scInfoTwo = new ShortcutInfo.Builder(SuperFanActivity.this, "superfan")
.setLongLabel("超级返")
.setShortLabel("超级返")
.setIcon(Icon.createWithResource(SuperFanActivity.this, R.drawable.fanli))
.setIntents(new Intent[]{new Intent("superFanActivity", Uri.EMPTY, SuperFanActivity.this,SuperFanActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)}).build();
scManager.setDynamicShortcuts(FanliApplication.shortCutInfos);
</pre>
取消快捷方式:根据快捷方式的id来进行取消,调用disableShortcuts方法实现,只有动态实现的可以取消
scManager.disableShortcuts(Arrays.asList(scInfoTwo.getId(),"该选项已取消"));
scManager.removeDynamicShortcuts(Arrays.asList(scInfoTwo.getId()));
android 7.1以上
2.功能说明
长按桌面app图标出现快捷方式列表,点击可跳转到app的指定界面,用户也可以将其作为一个单独的快捷方式
3.效果截图
3.技术实现
分为两种方式,静态xml配置和动态代码配置,二者各有优劣,xml配置不需要运行app就有了,但是快捷方式不可以取消。动态代码配置更灵活,可以在任意界面新增或者取消快捷方式
静态xml实现方式:新建xml资源文件,将需要内置的快捷方式写入<shortcuts>标签内,其中包括快捷方式的图标、名称、跳转的url等
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="yydb"
android:enabled="true"
android:icon="@drawable/fanli"
android:shortcutShortLabel="@string/yydb"
android:shortcutLongLabel="@string/yydb"
android:shortcutDisabledMessage="@string/yydb">
<intent
android:action="android.intent.action.VIEW"
android:data="需要跳转的url"
android:targetPackage="com.fanli.android.apps"
android:targetClass="com.fanli.android.basicarc.ui.activity.CustomUrlBridgeActivity" />
<categories android:name="android.shortcut.conversation"/>
</shortcut>
</shortcuts>
动态代码实现方式:需要先初始化shortcutinfo,给定快捷方式的属性,然后再调用setDynamicShortcuts告知系统改变快捷方式
ShortcutManager scManager = getSystemService(ShortcutManager.class);
ShortcutInfo scInfoTwo = new ShortcutInfo.Builder(SuperFanActivity.this, "superfan")
.setLongLabel("超级返")
.setShortLabel("超级返")
.setIcon(Icon.createWithResource(SuperFanActivity.this, R.drawable.fanli))
.setIntents(new Intent[]{new Intent("superFanActivity", Uri.EMPTY, SuperFanActivity.this,SuperFanActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)}).build();
scManager.setDynamicShortcuts(FanliApplication.shortCutInfos);
</pre>
取消快捷方式:根据快捷方式的id来进行取消,调用disableShortcuts方法实现,只有动态实现的可以取消
scManager.disableShortcuts(Arrays.asList(scInfoTwo.getId(),"该选项已取消"));
scManager.removeDynamicShortcuts(Arrays.asList(scInfoTwo.getId()));
阅读全文
0 0
- shortcuts实现
- Keyboard shortcuts
- eclipse shortcuts
- Firefox shortcuts
- MPlayer Shortcuts
- ubuntu shortcuts
- mplayer shortcuts
- Python Shortcuts
- Eclipse Shortcuts
- ORCAD ShortCuts
- Eclipse Shortcuts
- Terminal Shortcuts
- xcode shortcuts
- Rstudio shortcuts
- Eclipse-Shortcuts
- Bash Shortcuts
- eclipse shortcuts
- word-shortcuts
- 算法 直接插入排序 c语言
- Hihocoder-1545 小Hi和小Ho的对弈游戏(博弈)
- 使用struts2.5版本遇到的问题
- URAL 1519 Formula 1(插头DP)
- [简单DP]Tickets HDU
- shortcuts实现
- <Android 应用 之路> 每日一文简单版<Kotlin>
- Makefile相关函数
- 【Oracle】sql的使用总结
- HDU 5131 Song Jiang's rank list (确定排名经典问题)
- 将二叉搜索树转换成一个排序的双向链表
- Sublime Text3 + Golang搭建开发环境
- android nfc中MifareClassic格式的读写
- 隐藏状态栏(适用Android Studio)