WXR
WXR

Reputation: 591

how to use phonegap-2.9.0 camera and store in android device?

NOTE: I was being stupid, for so many things I tried the picture DOES save into my local storage but I kept on checking my gallery (always thought gallery would scan all the images) but somehow it's not in my gallery so I kept on thinking the image didn't save

I'm using phonegap 2.9.0 and playing with the camera API. The phonegap documentation even provided a full html example which you can just copy and paste the code into the www folder and deploy and camera works perfectly just that it wouldn't save the image taken into the local/sd storage. I'm trying to figure out how and been trying for a while can someone give me a hand?

I did do some research before I post this question. I did find a post:

Save image in local storage phonegap

but I tried the code there and somehow it didn't work for me. I also searched a few sites and posts and lots of them just mentioned adding saveToPhotoAlbum: true which was mentioned in the phonegap documentation and I tried which didn't work at all..

I looked through the phonegap 2.9.0 documentation, and saw permissions so I believe I need to add those codes too so I did...

in config.xml I added

<plugin name="Camera" value="org.apache.cordova.CameraLauncher" />

in AndroidManifest I added

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

and in index.html I just used the full example which phonegap. 2.9.0 provided. I think it's too must to paste it here but I believe this is where I need to add something into the code..

// A button will call this function
//
function capturePhoto() {
  // Take picture using device camera and retrieve image as base64-encoded string
  navigator.camera.getPicture(onPhotoDataSuccess, onFail,{ quality: 50,
    destinationType: destinationType.DATA_URL, saveToPhotoAlbum: true });
}

I thought by adding saveToPhotoAlbum: true would work but doesn't seem like it works though.

Can someone give me a hand? The documentation looks easy but gets frustrated when can't figure out what's wrong (:

Upvotes: 2

Views: 6387

Answers (2)

Kathir
Kathir

Reputation: 4377

1.destinationType: Camera.DestinationType.DATA_URL

DATA_URL returns base64 string only here image not store in album;

2.destinationType: Camera.DestinationType.FILE_URL

FILE_URL returns image url. here image stored in album.

if u need both i mean base64 string and image stored in album. you need do something

  • get url from camera success then use File API - FileReader (readAsDataURL) concepts in phonegap

    1. FILE_URL better for android DATA_URL crash the app sometimes for out memory error

Upvotes: 0

Divesh Salian
Divesh Salian

Reputation: 1455

Change this

destinationType: Camera.DestinationType.DATA_URL

to

destinationType: Camera.DestinationType.FILE_URI

It will return you the imageuri,For getting the exact location you can make use of filesystem api in phonegap

window.resolveLocalFileSystemURI(imageURI, resolveOnSuccess, fsFail);
function resolveOnSuccess(entry) {
var fileuri = entry.toURL();
//console.log(fileuri);
}

Upvotes: 5

Related Questions