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

android 创建快捷方式

2012年02月09日 ⁄ 综合 ⁄ 共 776字 ⁄ 字号 评论关闭

转载:http://blog.csdn.net/luck_apple/article/details/7173104

首先需要权限:

[html] view
plain
copy

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

[java] view
plain
copy

  1. Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");  
  2. ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon); //图标  
  3. intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);  
  4. intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,getString(R.string.app_name)); //名称  
  5. intent.putExtra("duplicate"false);  
  6.   
  7. Intent sIntent = new Intent(Intent.ACTION_MAIN);  
  8. sIntent.addCategory(Intent.CATEGORY_LAUNCHER);  
  9. sIntent.setClass(this, MainActivity.class);  
  10. intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, sIntent);  
  11. sendBroadcast(intent);  

抱歉!评论已关闭.