public static String replaceImageURLs(String content, final long entryId) { if (!TextUtils.isEmpty(content)) { boolean needDownloadPictures = NetworkUtils.needDownloadPictures(); final ArrayList<String> imagesToDl = new ArrayList<>(); Matcher matcher = IMG_PATTERN.matcher(content); while (matcher.find()) { String match = matcher.group(1).replace(" ", URL_SPACE); String imgPath = NetworkUtils.getDownloadedImagePath(entryId, match); if (new File(imgPath).exists()) { content = content.replace(match, "file://" + imgPath); } else if (needDownloadPictures) { imagesToDl.add(match); } } // Download the images if needed // if (!imagesToDl.isEmpty()) { // new Thread(new Runnable() { // @Override // public void run() { // FetcherService.addImagesToDownload(String.valueOf(entryId), imagesToDl); // Context context = MainApplication.getContext(); // context.startService(new Intent(context, FetcherService.class) // .setAction(FetcherService.ACTION_DOWNLOAD_IMAGES)); // } // }).start(); // } } return content; }