android 创建快捷方式

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

 

首先需要权限:

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

 

 

 

  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);  

posted on 2013-06-03 08:46  Bo.Zhang  阅读(137)  评论(0)    收藏  举报