现在的位置: 首页 > 综合 > 正文

android 创建快捷方式

2013年10月03日 ⁄ 综合 ⁄ 共 634字 ⁄ 字号 评论关闭

首先需要权限:

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

Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon); //图标
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,getString(R.string.app_name)); //名称
intent.putExtra("duplicate", false);

Intent sIntent = new Intent(Intent.ACTION_MAIN);
sIntent.addCategory(Intent.CATEGORY_LAUNCHER);
sIntent.setClass(this, MainActivity.class);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, sIntent);
sendBroadcast(intent);

抱歉!评论已关闭.