ITeye博客

创建应用快捷方式,且点击快捷方式回到应用,而不是重新启动应用!!

wfkbyni · 2012-12-12 16:38 · android · 移动开发 · Markdown

private void createShortCut() {

	Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
	shortcutIntent.setClassName(this, this.getClass().getName());
	shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
	shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
	shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);

	Intent intent = new Intent(
			"com.android.launcher.action.INSTALL_SHORTCUT");
	intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
	// 设置快捷方式名称
	intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
			getString(R.string.app_name));
	// 设置快捷方式图标
	intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
			Intent.ShortcutIconResource.fromContext(this,
					R.drawable.ic_launcher));
	// 防止重复创建
	intent.putExtra("duplicate", false);

	sendBroadcast(intent);

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。