如何使用适用于Android 7.1应用程序的ShortcutManager API创建动态应用程序快捷方式? [英] How to create dynamic app shortcut using ShortcutManager API for android 7.1 app?

查看:279
本文介绍了如何使用适用于Android 7.1应用程序的ShortcutManager API创建动态应用程序快捷方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android 7.1中,开发人员可以创建



检查Github示例中的应用程序快捷方式



检查 https:// developer .android.com / preview / shortcuts.html 快捷方式以获取更多信息。


In Android 7.1, developer can able to create AppShortCut.

We can create shortcut in two way:

  1. Static shortcuts using resources(XML) file.
  2. Dynamic shortcuts using ShortcutManager API.

So How to create a shortcut using ShortcutManager dynamically?

解决方案

Using ShortcutManager, we can create app dynamic app shortcut in following way:

ShortcutManager shortcutManager;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        shortcutManager = getSystemService(ShortcutManager.class);
        ShortcutInfo shortcut;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
            shortcut = new ShortcutInfo.Builder(this, "second_shortcut")
                    .setShortLabel(getString(R.string.str_shortcut_two))
                    .setLongLabel(getString(R.string.str_shortcut_two_desc))
                    .setIcon(Icon.createWithResource(this, R.mipmap.ic_launcher))
                    .setIntent(new Intent(Intent.ACTION_VIEW,
                            Uri.parse("https://www.google.co.in")))
                    .build();
            shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
        }


    }

String resources:

<string name="str_shortcut_two">Shortcut 2</string>
<string name="str_shortcut_two_desc">Shortcut using code</string>

Developer can also perform different tasks app shortcut using ShortcutManager:

Check Github example for App Shortcut

Check https://developer.android.com/preview/shortcuts.html and ShortcutManager to get more info.

这篇关于如何使用适用于Android 7.1应用程序的ShortcutManager API创建动态应用程序快捷方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆