如何应用程序的快捷方式添加到主屏幕 [英] How to add app's shortcut to the home screen

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

问题描述

我知道这是没有记录,也不会在每个设备上工作,但我看到越来越多的应用程序把他们的快捷方式在主屏幕上得到了安装后。 发现一堆code块怎么做,但对我来说他们不适合在一起。 这是我得到了现在。

I know it's not documented and won't work on every device, but I see more and more apps placing their shortcuts on the home screen after they got installed. Found bunch of code chunks how to do it but for me they don't fit together. This is what I got for now.

  1. 需要在清单中的权限。

  1. Need a permission in the manifest.

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

  • 创建活动的意图,应该被调用。 EX(从cgeek):

  • Create an Intent of activity that should be called. Ex (from cgeek):

    Intent shortcutIntent = new Intent();
    shortcutIntent.setClassName("com.example.androidapp", "SampleIntent");
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    

  • 创建快捷方式本身

  • Create shortcut itself

    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.icon));
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);
    

  • 我的问题是: 如果这code应该使加快捷的apk安装后?我想这code在发射活动,它创造坏了(另一回事)快捷方式,每次应用程序启动。

    My questions is: Where this code should go to make shortcut added after .apk installed? I tried this code in the launcher activity, it creates broken(another story) shortcut every time app starts.

    推荐答案

    据我所知,这是不是自己的应用程序的市场应用程序的可选功能。按照设计的应用程序不会收到被安装到一个关于它自己的广播。如果codeS工作,最快可以执行这是用户第一次启动应用程序。这就是说:

    As far as I know, that's an optional feature of the Market app, not of the apps themselves. By design an application does not receive a broadcast about itself being installed. If that codes works, the soonest you can execute it is the first time the user launches the app. That said:

    做的。不。自动。创建。应用程序。快捷键。

    Do. Not. Automatically. Create. App. Shortcuts.

    曾经。

    不要抢尽了用户的UI设计。

    Don't usurp the user's UI design.

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

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