如何在安装后自动创建快捷方式?
如何在安装后自动创建快捷方式?下面的代码不起作用!如何在安装后自动创建快捷方式?
private void createShortCut() {
Intent intent = new Intent(ACTION_INSTALL_SHORTCUT);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
intent.putExtra("duplicate", false);
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);//icon
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext() , MainActivity.class));
setResult(RESULT_OK, intent);
sendBroadcast(intent);
}
安装后无法自动创建快捷方式,因为安装后代码没有自动运行。
第一次启动后可能吗? – thecr0w 2012-04-13 08:59:02
然后你对Google Play商店中的应用说什么,他们自动创建快捷方式 – 2014-03-06 08:39:36
@JayVyas:Play商店应用安装程序正在这样做,而不是正在安装的应用。 – CommonsWare 2014-03-06 10:39:05
是的,创建快捷方式非常有可能是您的应用程序或任何第三方应用程序或系统应用程序。请遵循此示例代码。
try
{
for (int i = 0; i < packageNameArray.length; i++)
{
Intent shortcutIntent = Util.makeIntent(MyPreference.getAction(context), MyPreference.getCategory(context), packageNameArray[i], ActivityNameArray[i]);
Bitmap shortcutIcon2 = Util.confleteBitmap((UtilityClass.StringToBitMap(IconArray[i])), BitmapFactory.decodeResource(context.getResources(), R.drawable.shortcut_mark));
data.putExtra("android.intent.extra.shortcut.INTENT", shortcutIntent);
data.putExtra("android.intent.extra.shortcut.ICON", shortcutIcon2);
data.putExtra("android.intent.extra.shortcut.NAME", AppNameArray[i]);
//uninstalling shortcut to remove duplicacy
Intent intent = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
intent.putExtra("duplicate", false);
intent.putExtras(data);
context.sendBroadcast(intent);
}
}
catch (Exception e)
{
e.printStackTrace();
}
这里packagenamearray是您选择创建您通过快捷所有的应用程序,你应用程式包名在这里,如果你要创建只是你的应用程序快捷方式 activitynamearray是选择应用程序的activityname。
你检查过[这一个](http://*.com/questions/6337431/android-create-shortcuts-on-the-home-screen) – 2012-04-12 11:59:00