【问题标题】:How to add a widget as an icon when install android app安装android应用程序时如何将小部件添加为图标
【发布时间】:2012-03-24 08:35:01
【问题描述】:

我在 Play 商店中看到了一些应用程序,当安装这些应用程序时会自动添加一个图标(如果我们触及或任何其他原因来展示他们的新应用程序)。怎么做。

【问题讨论】:

    标签: android plugins android-widget presentation


    【解决方案1】:

    只需将其添加到您的清单中:

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

    并使用此代码:

    Intent shortcutIntent = new Intent();
    Intent i = new Intent();
    i.setClassName(getPackageName(), getPackageName());
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getPackageName());
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
    Intent.ShortcutIconResource.fromContext(getApplicationContext(),
                            R.drawable.icon));
    shortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            this.sendBroadcast(shortcutIntent);
    

    您可以将图标更改为您的应用程序图标并更改应用程序的名称

    【讨论】:

    • 感谢您的回复。我尝试将此代码用于我的应用程序,但它不起作用。我在 onCreate() 上添加了。
    • 我认为您没有将此权限添加到清单中,我正在检查我的代码然后将其发送到这里,将其添加到清单中:
    • 我加了。你能寄给我样品项目吗?谢谢
    • 谢谢.. 我想通过点击快捷方式打开应用程序,提前谢谢
    • 当我点击图标(快捷方式)时,我可以看到显示您的应用程序未安装在手机上的 toast 消息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 2015-05-10
    相关资源
    最近更新 更多