美文网首页
Android 8.0新特性 桌面图标菜单Shortcuts

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

作者: jessing | 来源:发表于2018-01-19 17:04 被阅读1223次

    前言

    最近更新了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

    相关文章

      网友评论

          本文标题:Android 8.0新特性 桌面图标菜单Shortcuts

          本文链接:https://www.haomeiwen.com/subject/rgxaoxtx.html