如何添加主屏幕快捷方式,无需安装后启动应用程序 [英] How to add home screen shortcut without launching app after installation

查看:425
本文介绍了如何添加主屏幕快捷方式,无需安装后启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下code以添加在主屏幕上的快捷方式

I am using following code to add shortcut at home screen

private void createShortcut() {
        String appName = getString(R.string.app_name);

        // Adding shortcut for MainActivity
        // on Home screen
        Intent shortcutIntent = new Intent(getApplicationContext(),
                SplashActivity.class);

        shortcutIntent.setAction(Intent.ACTION_MAIN);
        shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY );
        //shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        Intent addIntent = new Intent();
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
        addIntent.putExtra("duplicate", false);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,

            Intent.ShortcutIconResource.fromContext(
                        getApplicationContext(), R.drawable.ic_launcher));

        addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        getApplicationContext().sendBroadcast(addIntent);

    }

和它的清单批准

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

crateShortcut()code是在我的主要活动类。当我启动应用程序的快捷方式成功创建的主屏幕。
我想,当有人通过.apk文件,它会自动创建快捷方式安装我的应用程序(不启动应用程序)主屏幕上。我怎样才能做到这一点?是否有它告诉安装的应用程序的广播?
 先谢谢了。

crateShortcut() code is in my main activity class. When I launch the app shortcut successfully creates at home screen. I want when some one install my app through .apk it automatically create shortcut (without launching the app) on home screen. How I can do this? Is there any broadcast which tells that app installed?? Thanks in advance.

推荐答案

在谷歌玩,你可以设置这个选项安装后创建快捷方式回家。

In Google play you can set this option to create home shortcut after installation.

这篇关于如何添加主屏幕快捷方式,无需安装后启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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