title: How do I make a downloaded image show up in the Device's Gallery?
body: <p>I have a phonegap photo-gallery application, with an option to download images to the device. </p>
  
  <p>Currently, I'm able to save images into the SDCard of the device, but they don't show up in the Device's Photo-Library / Gallery application.</p>
  
  <p>Here is the code I'm using:</p>
  
  <pre><code>var remoteFile = encodeURI($("#imageView_content").find("img").attr("src"));
  var localFileName = remoteFile.substring(remoteFile.lastIndexOf('/') + 1);
  
  var downloadSuccess = function() {
      alert("Download sucessful!\nFile Saved at: " + localFileName);
  };
  var handleDownloadedFile = function(entry) {
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, downloadSuccess, fail);
  };
  var startFileTransfer = function(fileEntry) {
      var localPath = fileEntry.fullPath;
      var ft = new FileTransfer();
      ft.download(remoteFile, localPath, handleDownloadedFile, fail);
  };
  var createLocalFile = function(dir) {
      dir.getFile(localFileName, {
          create : true,
          exclusive : false
      }, startFileTransfer, fail);
  };
  var createPhotosDir = function(fileSys) {
      fileSys.root.getDirectory("myAppName", {
          create : true,
          exclusive : false
      }, createLocalFile, fail);
  };
  
  window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, createPhotosDir, fail);
  </code></pre>
  
  <p>I am using <a href="https://build.phonegap.com" rel="nofollow">https://build.phonegap.com</a> to build the app</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I'm trying to use a path depending on the Device, but this doesn't seem to be working: </p>
  
  <ul>
  <li>On iOS (Simulator), the call fails - Path: <code>file:///private/var/root/Media/DCIM/100APPLE/myApp/</code></li>
  <li>On Android, the download is successful,  but the images still don't show up on the Gallery until the device is restarted - Path: <code>dcim/myApp/</code></li>
  <li>I couldn't test on BlackBerry, but I've set it up to try <code>file:///SDCard/BlackBerry/pictures/myApp/</code>, first and <code>file:///store/home/user/pictures/myApp/</code> on failure</li>
  </ul>
  
  <p>Here's the Device detection code:</p>
  
  <pre><code>var platform = (device.platform || navigator.userAgent).toLowerCase();
  if (platform.match(/iphone/i) || platform.match(/ipad/i) || platform.match(/ios/i)) {
      window.resolveLocalFileSystemURI("file:///private/var/root/Media/DCIM/100APPLE/", createPhotosDir_fromDir, callPhotosDir);
  } else if (platform.match(/blackberry/i) || navigator.userAgent.toLowerCase().match(/blackberry/i)) {
      window.resolveLocalFileSystemURI("file:///SDCard/BlackBerry/pictures/", createPhotosDir_BB, callPhotosDir);
  } else if (platform.match(/android/i)) {
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, createPhotosDir_Droid, callPhotosDir);
  } else {
      callPhotosDir();
  }
  </code></pre>
  
  <p>And here are the directory selection functions:</p>
  
  <pre><code>var callPhotosDir = function() {
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, createPhotosDir, fail);
  };
  var createPhotosDir_fromDir = function(dir) {
      dir.getDirectory("myApp", {
          create : true,
          exclusive : false
      }, createLocalFile, callPhotosDir);
  };
  var createPhotosDir_Droid = function(fileSys) {
      fileSys.root.getDirectory("dcim/myApp", {
          create : true,
          exclusive : false
      }, createLocalFile, callPhotosDir);
  };
  var createPhotosDir_BB = function(dir) {
      dir.getDirectory("myApp", {
          create : true,
          exclusive : false
      }, createLocalFile, function() {
          window.resolveLocalFileSystemURI("file:///store/home/user/pictures/", createPhotosDir_fromDir, callPhotosDir);
      });
  };
  </code></pre>