转自: http://shaotao.blog.51cto.com/7606729/1332258
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); //只第一次运行时生成,以后就不生成了 SharedPreferences preferences = getSharedPreferences( "isfrist_file" , Context.MODE_PRIVATE); boolean isFirst = preferences.getBoolean( "isfrist" , true ); if (isFirst) { //创建快捷方式 createDeskShortCut(); } SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean( "isfrist" , false ); editor.commit(); } public void createDeskShortCut() { // 创建快捷方式的Intent Intent shortcut = new Intent( "com.android.launcher.action.INSTALL_SHORTCUT" ); // 不允许重复创建 shortcut.putExtra( "duplicate" , false ); // 需要现实的名称 shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name)); // 快捷图片 Parcelable icon = Intent.ShortcutIconResource.fromContext( getApplicationContext(), R.drawable.ic_launcher); shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon); // 快捷方式入口 Intent intent = new Intent(getApplicationContext(), MainActivity. class ); // 下面两个属性是为了当应用程序卸载时,删除桌面上的快捷方式 intent.setAction( "android.intent.action.MAIN" ); intent.addCategory( "android.intent.category.LAUNCHER" ); // 点击快捷图片,运行的程序主入口 shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent); // 发送广播 OK sendBroadcast(shortcut); } }


还要添加创建快捷方式权限

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




更多相关文章

  1. eclipse运行android时Console最后提示Done!不运行程序
  2. android升级数据库(Sqlite)简单示例
  3. android 创建快捷方式
  4. android之File文件简单操作
  5. Android之Button样式
  6. Android(安卓)中 上下文Context理解
  7. 【Android】使用代码动态创建布局
  8. ubuntu下Android源码下载编译运行,单独编译运行
  9. android 创建快捷图标demo

随机推荐

  1. Android重力感应示例
  2. Android程序开发入门——进程生命周期
  3. Android事件分发机制--ViewGroup(二)
  4. 使用多字节字符集的跨平台(PC、Android、I
  5. Android(安卓)手势小试牛刀
  6. 关于多设备登录的思考与实现
  7. Android(安卓)屏幕适配问题
  8. 短视频技术详解:Android端的短视频开发技
  9. Android下对Cookie的读写操作(附Demo)
  10. Android(安卓)屏蔽蓝牙连接时的首次配对