Android 8.0新特性 桌面图标菜单Shortcuts

前言

最近更新了Android8.0,发现了有个新功能,就是桌面图标上长安可以弹出菜单,如图。点击可进入相应的页面。作为程序员你肯定想知道这是怎么做出来的吧,于是我就翻过去看了看。


系统

正文

            这个功能叫做APP Shortcuts,有两种注册的方法,静态注册和动态注册。

1.静态注册

在启动界面的下添加 meta-data标签


在xml文件下新建xml文件shortcut.xml


搞定

2.动态注册

添加

ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "id1")     .setShortLabel("Web site")     .setLongLabel("Open the web site")     .setIcon(Icon.createWithResource(context, R.drawable.icon_website))     .setIntent(new Intent(Intent.ACTION_VIEW,                    Uri.parse("https://www.mysite.example.com/")))     .build(); shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));

移除

shortcutManager.disableShortcuts(Arrays.asList("news","email","search","web"));       


example:



结语

其实很简单,还有其他的一些API请到谷歌开发者中心区查看吧,英语不好,看不太懂。

Github:https://github.com/jessing/LaucherBadgeDemo/tree/master

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。