Android创建和删除桌面快捷方式


[java] view plain copy print ?
  1. /**
  2. *为程序创建桌面快捷方式
  3. */
  4. privatevoidaddShortcut()
  5. {
  6. Intentshortcut=newIntent(
  7. "com.android.launcher.action.INSTALL_SHORTCUT");
  8. //快捷方式的名称
  9. shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
  10. getString(R.string.app_name));
  11. shortcut.putExtra("duplicate",false);//不允许重复创建
  12. //指定当前的Activity为快捷方式启动的对象:如com.everest.video.VideoPlayer
  13. //注意:ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序
  14. ComponentNamecomp=newComponentName(this.getPackageName(),"."
  15. +this.getLocalClassName());
  16. shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,newIntent(
  17. Intent.ACTION_MAIN).setComponent(comp));
  18. //快捷方式的图标
  19. ShortcutIconResourceiconRes=Intent.ShortcutIconResource.fromContext(
  20. this,R.drawable.icon);
  21. shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconRes);
  22. sendBroadcast(shortcut);
  23. }
  24. /**
  25. *删除程序的快捷方式
  26. */
  27. privatevoiddelShortcut()
  28. {
  29. Intentshortcut=newIntent(
  30. "com.android.launcher.action.UNINSTALL_SHORTCUT");
  31. //快捷方式的名称
  32. shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
  33. getString(R.string.app_name));
  34. //指定当前的Activity为快捷方式启动的对象:如com.everest.video.VideoPlayer
  35. //注意:ComponentName的第二个参数必须是完整的类名(包名+类名),否则无法删除快捷方式
  36. StringappClass=this.getPackageName()+"."
  37. +this.getLocalClassName();
  38. ComponentNamecomp=newComponentName(this.getPackageName(),appClass);
  39. shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,newIntent(
  40. Intent.ACTION_MAIN).setComponent(comp));
  41. sendBroadcast(shortcut);
  42. }

更多相关文章

  1. Android获取、设置桌面
  2. 设置Android程序的默认安装位置
  3. Android完全退出程序、线程
  4. android Socket实现简单聊天小程序
  5. 最全的PHP开发Android应用程序
  6. 用Gradle 构建android程序

随机推荐

  1. Android改变文件的权限
  2. 了解 uri, content provide,包括 data and
  3. 【Android】数据存储之SQLite
  4. Android关于LinearLayout和RelativeLayou
  5. Android的介绍
  6. 百度招聘Android客服端(1)
  7. 在Android(安卓)studio中建立Java工程
  8. android与tomcat服务器交互实例
  9. android Service Activity三种交互方式(付
  10. 【进阶篇】Android学习笔记——TextInput