免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2441 | 回复: 0
打印 上一主题 下一主题

创建程序桌面快捷方式 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-06-22 19:18 |只看该作者 |倒序浏览
创建程序桌面快捷方式
  1. Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");  

  2.     //快捷方式的名称  
  3.     shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));  
  4.     shortcut.putExtra("duplicate", false); //不允许重复创建  

  5.     //指定当前的Activity为快捷方式启动的对象: 如 com.everest.video.VideoPlayer  
  6.     //注意: ComponentName的第二个参数必须加上点号(.),否则快捷方式无法启动相应程序  
  7.     ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName());  
  8.     shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));  
  9.     //快捷方式的图标  
  10.     ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);  
  11.     shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);  

  12.     sendBroadcast(shortcut);  

  13. 添加权限:

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


复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP