阳光网驿-企业信息化交流平台【DTC零售连锁全渠道解决方案】

 找回密码
 注册

QQ登录

只需一步,快速开始

扫描二维码登录本站

手机号码,快捷登录

老司机
查看: 1150|回复: 0

[转帖] Android应用自动添加桌面图标

[复制链接]
  • TA的每日心情
    开心
    2012-3-7 10:15
  • 签到天数: 11 天

    [LV.3]偶尔看看II

    发表于 2012-1-17 09:58:50 | 显示全部楼层 |阅读模式
    每个可以交互的应用,在项目清单文件中都有Launcher类,除了提示系统这个Activity是入口函数外,还会在应用列表中添加一个应用的快捷图标。本文讲述Launcher通过自己注册的InstallShortCutReceiver和UnInstallShortCutReceiver实现了快捷方式图标的生成与移除过程,分析外部apk实用Intent请求生成快捷方式和移除快捷方式图标的问题。

    添加图标:
    Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
    // 是否可以有多个快捷方式的副本,参数如果是true就可以生成多个快捷方式,如果是false就不会重复添加 intent.putExtra("duplicate", false);
    Intent intent2 = new Intent(Intent.ACTION_MAIN);
    intent2.addCategory(Intent.CATEGORY_LAUNCHER);
    // 删除的应用程序的ComponentName,即应用程序包名+activity的名字 intent2.setComponent(new ComponentName(this.getPackageName(), this.getPackageName() + ".Main"));
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent2);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this,
    R.drawable.icon));
    sendBroadcast(intent);
    需要添加的权限:
    <uses-permission android:name=“com.android.launcher.permission.INSTALL_SHORTCUT” />


    删除图标:
    Intent intent = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT" );
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
    // 要删除的应用程序的ComponentName,即应用程序包名+activity的名字 intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent()
    .setComponent(new ComponentName(info.activityInfo.packageName,
    info.activityInfo.name)).setAction("android.intent.action.MAIN"));
    sendBroadcast(intent);
    添加删除的权限:

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

    楼主热帖
    启用邀请码注册,提高发帖质量,建设交流社区
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    快速回复 返回顶部 返回列表