如你所知,当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.