gy1422871384
gy1422871384
采纳率100%
2013-10-12 04:00 阅读 4.9k

如何让launcher自动为新安装apk创建快捷方式到桌面

这是关于launcher的开发,目的是launcher 自动给新安装的app创建快捷方式不是 app给自己创建快捷方式到workspace。求指点,谢谢!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    gy1422871384 gy1422871384 2013-10-23 08:42

    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");

    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, info.title.toString());
    Intent respondIntent = info.intent;
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, respondIntent);
    Context pkgContext = null;
    int iconIdentifier = 0;
    PackageManager manager = mLauncher.getPackageManager();
    System.out.println("manager="+manager);
    android.content.pm.ApplicationInfo appInfo;
    try {
    appInfo = manager.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
    iconIdentifier = appInfo.icon;
    } catch (NameNotFoundException e1) {
    e1.printStackTrace();
    }
    try {
    pkgContext = mLauncher.createPackageContext(packageName,Context.CONTEXT_IGNORE_SECURITY
    | Context.CONTEXT_INCLUDE_CODE);
    } catch (NameNotFoundException e) {
    e.printStackTrace();
    }
    if (pkgContext != null) {
    ShortcutIconResource iconRes = Intent.ShortcutIconResource
    .fromContext(pkgContext, iconIdentifier);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconRes);
    }
    mLauncher.sendBroadcast(shortcut);

    点赞 2 评论 复制链接分享
  • pingchuanyang 羊男 2013-10-13 03:02

相关推荐