gy1422871384 2013-10-12 04:00 采纳率: 100%
浏览 5029
已采纳

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

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

  • 写回答

2条回答 默认 最新

  • 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);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料