您的位置:首页 > 移动开发 > Android开发

android 创建快捷方式

2012-01-03 17:11 267 查看
首先需要权限:
<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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: