NativeScript / nativescript-camera

NativeScript plugin to empower using device camera.
Apache License 2.0
92 stars 47 forks source link

saveToFile not showing images into gallery #222

Closed kdmakwana43 closed 4 years ago

kdmakwana43 commented 4 years ago

Hello, I created a nativescript app for camara related app. I am taking a photo using nativescript-camara module.

once user take a photo I am showing that image preview, as well as user can rename that image name. When user save that image I stored into a specific folder and removing preview image which stored by nativescript-camara module.

after that, i can see that image in the gallery but not the original image, I can only blank image in the gallery. I also checked that image is exist on that location where is saved it. That means, Image saving work perfects but not showing that image in the gallery immediately. After 5-10 minutes i can see that image in gallery. But not an immediately.

here is some screenshot

Gallery view Screenshot 2019-09-13 at 12 18 20 PM

Opened that broken image WhatsApp Image 2019-09-13 at 11 58 09 AM (1)

The image on his location WhatsApp Image 2019-09-13 at 11 58 09 AM

kdmakwana43 commented 4 years ago

Here is my code for save image

const path = FileSystem.path.join(this.appRootFolder, `${this.imageName}.jpg`);
      const source = new ImageSource();
      source.fromAsset(this.newImageAsset).then((result) => {
        const saved = source.saveToFile(path, "jpg");
        if (saved) {
        //his.imageName will provide user's provided image name
          this.showAlert(`Saved image ${this.imageName}.jpg`);
          setTimeout(() => {
            this.removeImage(); // this will remove preview image
          },1000);
        }
      });
kdmakwana43 commented 4 years ago

Finally! i solved this issue, I scanned media and its done. Here is my code.

var callback = new android.media.MediaScannerConnection.OnScanCompletedListener({
      onScanCompleted: function (path, uri) {
          console.log(path)
        }
    });

    android.media.MediaScannerConnection.scanFile(applicationModule.android.context, [path], null, callback);