如何为非活动类创建应用程序快捷方式

时间:2019-09-30 17:17:33

标签: java android

我为非活动性类创建了应用程序快捷方式。非活动类在主活动上创建自定义对话框视图。但我点击了表示未安装该应用程序的快捷方式图标。如何修复它。请帮帮我。

我尝试过但没有找到解决方案。

    public void createShortcut(){
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
            ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);


            Intent intent = new Intent(this, ClassA.class);
            intent_bal.setAction(Intent.ACTION_VIEW);

            ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(this,"shortcut1")
                    .setShortLabel("test1")
                    .setLongLabel("tessssst1")
                    .setIcon(Icon.createWithResource(this, R.drawable.ic_shortcut))
                    .setIntent(intent)
                    .build();

            shortcutManager.addDynamicShortcut(Collections.singletonList(shortcutInfo));
        }
    }

0 个答案:

没有答案