我怎么能放在发射器的主屏幕应用程序图标? [英] How can I place app icon on launcher home screen?

查看:208
本文介绍了我怎么能放在发射器的主屏幕应用程序图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如你所知,当nomally安装应用程序时,图标将在启动菜单屏幕上创建的。 我想要做的是安装过程中创建的用户的主屏幕上的图标。 (没有$ 5秒p $ pssing图标。)

As you know, when app is nomally installed, icon is created at launcher menu screen. What I want to do is create icon at user home screen during installation. (without pressing icon for 5 seconds.)

我听到这从另一个源只需添加

I heard this from another source to just add

<category android:value="android.intent.category.HOME" />

要AndroidManifest.xml文件,但没有奏效。

to AndroidManifest.xml file, but it didn't work.

有没有其他办法做到这一点?

Is there any other way to do it?

推荐答案

您可以使用此:

Intent shortcutIntent = new Intent();
shortcutIntent.setClassName("packageName", "className");
//shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

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));
//intent.putExtra("duplicate", false);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            context.sendBroadcast(addIntent);

您必须使用以下权限在AndroidManaifest.xml

You have to use following permission in your AndroidManaifest.xml

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

您可以根据您的需要使用评论code。

You can use the commented code according to your requirements.

需要注意的是,也许,以上的API没有记载。但是,它的工作原理。

Note that, perhaps, above API is not documented. But it works.

这篇关于我怎么能放在发射器的主屏幕应用程序图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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