灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:3166回复:0

android直接创建桌面快捷方式

楼主#
更多 发布于:2012-09-06 13:51

通过launcher源码可以看到创建快捷方式是通过
- <receiver Android:name="com.Android.launcher2.InstallShortcutReceiver" Android:permission="com.Android.launcher.permission.INSTALL_SHORTCUT">
-     <intent-filter>
    <action Android:name="com.Android.launcher.action.INSTALL_SHORTCUT" />
  </intent-filter>
</receiver>
生成快捷方式
我们可以在程序启动时直接发送广播创建桌面快捷方式
private void createShortCut(){
        Intent intent=new Intent("com.Android.launcher.action.INSTALL_SHORTCUT");//action
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));//快捷方式名字
        intent.putExtra("duplicate", false); //是否重复创建快捷方式
        Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);//icon
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext() , BatteryProfile.class)); //启动界面
        sendBroadcast(intent);//发送广播
    }
我们需要在在mainfest.xml加入以下权限
  <uses-permission Android:name="com.Android.launcher.permission.INSTALL_SHORTCUT"/>


喜欢0 评分0
游客

返回顶部