code: public static Bundle findBundle(BundleContext context, String packageName, String versionRange)
      {
          if (context == null)
              return null;
          Bundle[] bundles = context.getBundles();
          Bundle bestBundle = null;
          for (Bundle bundle : bundles)
          {
              if (packageName != null)
              {
                  Dictionary<?, ?> dictionary = bundle.getHeaders();
                  String packages = (String)dictionary.get(Constants.EXPORT_PACKAGE);
                  Version bundleVersion = new Version((String)dictionary.get(Constants.BUNDLE_VERSION));
  
                  StringBuilder sb = new StringBuilder(packages == null ? "" : packages);
                  while (true)
                  {
                      int start = sb.indexOf("=\"");
                      if (start == -1)
                          break;
                      int end = sb.indexOf("\"", start + 2);
                      if ((start > -1) && (end > -1))
                          sb.delete(start, end + 1);
                      else
                          break;  // never
                  }
                  while (true)
                  {
                      int semi = sb.indexOf(";");
                      if (semi == -1)
                          break;
                      int comma = sb.indexOf(",", semi);
                      if (comma == -1)
                          comma = sb.length();
                      else if (sb.charAt(comma + 1) == ' ')
                          comma++;
                      if ((semi > -1) && (comma > -1))
                          sb.delete(semi, comma);
                      else
                          break;  // never
                  }
                  
                  String[] packs = sb.toString().split(",");
                  for (String pack : packs)
                  {
                      if (packageName.equals(pack))
                      {
                          if (isValidVersion(bundleVersion, versionRange))
                              bestBundle = bundle;
                      }
                  }
              }
          }
          
          return bestBundle;
      }
docs: Find the currently installed bundle that exports this package.
  @param context
  @param resource
  @return