camera.getPicture - Application is not restored

1,120 views
Skip to first unread message

Pranav

unread,
Nov 6, 2011, 1:35:02 AM11/6/11
to phonegap
Hi,

I used the following in my application to take the picture from device
camera -

navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality:
50 });

Camera opens and I am able to take photo but after photo is taken, the
camera application does not close and my application is not restored.

I am using LG Optimus device with Android 2.2

Regards,
Pranav

Simon MacDonald

unread,
Nov 6, 2011, 8:06:33 AM11/6/11
to phon...@googlegroups.com
Hey,
I'm not sure how it works on the LG but after you take a picture on my
Samsung you have to "save" the picture before it returns to the
application.
You should change your getPicture() method to be:

navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality:
50, destinationType: Camera.DestinationType.FILE_URI });

Frequently the size of the Base64 encoded image causes and out of
memory error so I recommend to everyone they use the FILE_URI return
type.

As well make sure you have put:

android:configChanges="orientation|keyboardHidden"

in your AndroidManifest.xml. If not the main html page will reload
when you return from the camera.

Simon Mac Donald
http://hi.im/simonmacdonald

> --
> You received this message because you are subscribed to the Google
> Groups "phonegap" group.
> To post to this group, send email to phon...@googlegroups.com
> To unsubscribe from this group, send email to
> phonegap+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/phonegap?hl=en?hl=en
>
> For more info on PhoneGap or to download the code go to www.phonegap.com

Pranav

unread,
Nov 6, 2011, 11:27:37 PM11/6/11
to phonegap
Hi Simon,

I tried your suggestion but it also did not work. After taking photo,
camera is still open and I do not get option to "save" the picture.
And my application is never restored.

Regards,
Pranav

On Nov 6, 6:06 pm, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> Hey,
> I'm not sure how it works on the LG but after you take a picture on my
> Samsung you have to "save" the picture before it returns to the
> application.
> You should change your getPicture() method to be:
>
>     navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality:
> 50, destinationType: Camera.DestinationType.FILE_URI });
>
> Frequently the size of the Base64 encoded image causes and out of
> memory error so I recommend to everyone they use the FILE_URI return
> type.
>
> As well make sure you have put:
>
>     android:configChanges="orientation|keyboardHidden"
>
> in your AndroidManifest.xml. If not the main html page will reload
> when you return from the camera.
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald

Simon MacDonald

unread,
Nov 6, 2011, 11:48:53 PM11/6/11
to phon...@googlegroups.com
Run "adb logcat" so we can see what is going on.

Simon Mac Donald
http://hi.im/simonmacdonald

Pranav

unread,
Nov 7, 2011, 12:33:24 AM11/7/11
to phonegap
Thanks Simon for quick reply.

Shall I grep "D/CameraApp" and send across only the Camera logs or
attach the entire logs. Also I do not see the way to attach the file
here. I have to copy and paste it :)

Regards,
Pranav

On Nov 7, 9:48 am, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> Run "adb logcat" so we can see what is going on.
>

Simon MacDonald

unread,
Nov 7, 2011, 9:02:21 AM11/7/11
to phon...@googlegroups.com
Create a gist on https://gist.github.com/ as it is an effective way to
share logs without having to paste it all in an email.

Pranav

unread,
Nov 7, 2011, 10:31:00 AM11/7/11
to phonegap
Hi Simon,

Logs are here -
https://gist.github.com/1345270

Operations -

1. Launched the application
2. Link on the application, opens the camera (API used as suggested by
you)
3. Photo is taken
4 Since there is no option of saving the file and no way to return
back to application, I deleted the photo ( After taking photo, it gave
me options to delete the photo, take new photo, rename the file name
and NO option to update, save as etc)

Regards,
Pranav


On Nov 7, 7:02 pm, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> Create a gist onhttps://gist.github.com/as it is an effective way to
> share logs without having to paste it all in an email.
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald

LucyJp

unread,
Nov 8, 2011, 8:42:58 AM11/8/11
to phonegap
Hi Simon & Pranav,

I have same issue using Motorola Droid Android 2.2.2/phonegap 1.1.

Hit OK always brings back to the camera app and does not call success
call back. (The camera app provide OK, retake, and cancel buttons.)

Addition to picture, navigator.device.capture.captureVideo does
strange on this device. I have to start/stop recording, hit OK, start/
stop recording, and hit OK then success call back is got called.

CaptureAudio does not have issue.

Our mobile app works for Samsung galaxy tablet 10.0, Motorola Atrix
Android 2.3.4, Motorola Droid X 2.3.3. But has issue with Motorola
Droid Android 2.2.2.

Simon, would you be possible to tell something from log file? I posted
log at git://gist.github.com/1347716.git for getPicture process.
and line 50 is just before calling navigator.camera.getPicture, and I
have console.log in success call back but it does not show up in log
which I believe that it is not invoked either error call back.

Strange was that when I add alert message for each method including
success call back, we were able to take a picture, click ok, success
call back was got called, and got the picture. But that happened only
once and never be able to reproduce it.

Please suggest me something if you can.

Device that has issue:
Motorola Droid
Model: A855
Android version 2.2.2

Phonegap: 1.1

Thank you



On Nov 7, 10:31 am, Pranav <vpra...@gmail.com> wrote:
> Hi Simon,
>
> Logs are here -https://gist.github.com/1345270
>
> Operations -
>
> 1. Launched theapplication
> 2. Link on theapplication, opens the camera (API used as suggested by
> you)
> 3. Photo is taken
> 4 Since there is no option of saving the file and no way to return
> back toapplication, I deleted the photo ( After taking photo, it gave
> me options to delete the photo, take new photo, rename the file name
> and NO option to update, save as etc)
>
> Regards,
> Pranav
>
> On Nov 7, 7:02 pm, Simon MacDonald <simon.macdon...@gmail.com> wrote:
>
>
>
> > Create a gist onhttps://gist.github.com/asit is an effective way to
> > share logs without having to paste it all in an email.
>
> > Simon Mac Donaldhttp://hi.im/simonmacdonald
>
> > On Mon, Nov 7, 2011 at 12:33 AM, Pranav <vpra...@gmail.com> wrote:
> > > Thanks Simon for quick reply.
>
> > > Shall I grep "D/CameraApp" and send across only the Camera logs or
> > > attach the entire logs. Also I donotsee the way to attach the file
> > > here. I have to copy and paste it :)
>
> > > Regards,
> > > Pranav
>
> > > On Nov 7, 9:48 am, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> > >> Run "adb logcat" so we can see what is going on.
>
> > >> Simon Mac Donaldhttp://hi.im/simonmacdonald
>
> > >> On Sun, Nov 6, 2011 at 11:27 PM, Pranav <vpra...@gmail.com> wrote:
> > >> > Hi Simon,
>
> > >> > I tried your suggestion but it also didnotwork. After taking photo,
> > >> > camera is still open and I donotget option to "save" the picture.
> > >> > And myapplicationis neverrestored.
>
> > >> > Regards,
> > >> > Pranav
>
> > >> > On Nov 6, 6:06 pm, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> > >> >> Hey,
> > >> >> I'mnotsure how it works on the LG but after you take a picture on my
> > >> >> Samsung you have to "save" the picture before it returns to the
> > >> >>application.
> > >> >> You should change your getPicture() method to be:
>
> > >> >>     navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality:
> > >> >> 50, destinationType: Camera.DestinationType.FILE_URI });
>
> > >> >> Frequently the size of the Base64 encoded image causes and out of
> > >> >> memory error so I recommend to everyone they use the FILE_URI return
> > >> >> type.
>
> > >> >> As well make sure you have put:
>
> > >> >>     android:configChanges="orientation|keyboardHidden"
>
> > >> >> in your AndroidManifest.xml. Ifnotthe main html page will reload
> > >> >> when you return from the camera.
>
> > >> >> Simon Mac Donaldhttp://hi.im/simonmacdonald
>
> > >> >> On Sun, Nov 6, 2011 at 1:35 AM, Pranav <vpra...@gmail.com> wrote:
>
> > >> >> > Hi,
>
> > >> >> > I used the following in myapplicationto take the picture from device
> > > For more info on PhoneGap or to download the code go towww.phonegap.com- Hide quoted text -
>
> - Show quoted text -

LucyJp

unread,
Nov 8, 2011, 8:57:21 AM11/8/11
to phonegap
Hi Simon,

Please see log at https://gist.github.com/1347716 (sorry added wrong
url in previous post).

Thank you
> > > Create a gist onhttps://gist.github.com/asitis an effective way to
> > > > For more info on PhoneGap or to download the code go towww.phonegap.com-Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -

LucyJp

unread,
Nov 8, 2011, 12:24:26 PM11/8/11
to phonegap
We found that using other camera app, getPicture and captureVideo
works as expected but using built in camera app does not work. Does
this tell you anything?

Other camera app from market - “Camera 360” and “Vignette Demo”

Any thought?

Thank you

On Nov 8, 8:57 am, LucyJp <kayok...@hotmail.com> wrote:
> Hi Simon,
>
> Please see log athttps://gist.github.com/1347716 (sorry added wrong
> > > > Create a gist onhttps://gist.github.com/asitisan effective way to
> > > > > For more info on PhoneGap or to download the code go towww.phonegap.com-Hidequoted text -

TehSharpie

unread,
Nov 7, 2011, 11:01:12 AM11/7/11
to phonegap
Hello there,
i've got the exact same problem and have additions.
Using getPicture or capture.CaptureImage of course leads to same
results. Library or Camera, quality 20 or above, w/h to 100px (btw
these options do _not_ get a picture with these settings, whats in my
gallery then is a full sized img as i can tell. FileURI or imgURL, it
makes no difference at all. After save or choosing a pic in the
gallery the app is reset. Cancelling the Process brings the app, with
the former "view" and the error callback.
Using the full example from the docs for 1.1.0 is not working:
Putting "pictureSource=navigator.camera.PictureSourceType;" in the
deviceReady functions leads to errors exiting the js file. (My
application is working to fully extend without this.)

Research brings me to Simon Mac Donald's (hello) Blogpost about
changes in 1.1.0 which shows an example which differs from the docs to
use the camera.

No Approach i have taken gets me results. The App resets always. I
found several people complaining that the callBackSuccess doesnt work
at all, seems legit!
Are there options to use an older phonegap version or compile to lower/
older Android Versions to make this work on 2.3.3/3.2 devices?

My testing Devices were: 2.3.3 Samsung galaxy Si9000GT and emulator on
Linux.

What really annoys me, is the fact, that half of the phonegap
functions i used as documented were not working or not working as
described and ate much project time until now.
If im not able to import at least a pic in a size, that i can upload
it to a server, the whole project will be broke.

PS: The broken "exit" method for minsdkversion > 2 is a desaster, if
backbutton overwritten.

Regards,
TehSharpie

On Nov 7, 4:31 pm, Pranav <vpra...@gmail.com> wrote:
> Hi Simon,
>
> Logs are here -https://gist.github.com/1345270
>
> Operations -
>
> 1. Launched the application
> 2. Link on the application, opens the camera (API used as suggested by
> you)
> 3. Photo is taken
> 4 Since there is no option of saving the file and no way to return
> back to application, I deleted the photo ( After taking photo, it gave
> me options to delete the photo, take new photo, rename the file name
> and NO option to update, save as etc)
>
> Regards,
> Pranav
>
> On Nov 7, 7:02 pm, Simon MacDonald <simon.macdon...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Create a gist onhttps://gist.github.com/asit is an effective way to

Simon MacDonald

unread,
Nov 15, 2011, 10:06:48 AM11/15/11
to phon...@googlegroups.com
Sorry, I've been away and not able to keep up on emails as well as
normal. That is very confusing that you don't get an option to save a
photo in the LG. I'm betting they've replaced the Camera app with one
of their own.

One thing I did notice in the logs but I don't think it is related is:

E/WindowManager(22019): Activity com.test.activity.testActivity has
leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44c56818
that was originally added here
E/WindowManager(22019): android.view.WindowLeaked: Activity
com.test.activity.testActivity has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@44c56818 that
was originally added here
E/WindowManager(22019): at android.view.ViewRoot.<init>(ViewRoot.java:247)
E/WindowManager(22019): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
E/WindowManager(22019): at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
E/WindowManager(22019): at
android.view.Window$LocalWindowManager.addView(Window.java:424)
E/WindowManager(22019): at android.app.Dialog.show(Dialog.java:241)
E/WindowManager(22019): at
android.app.AlertDialog$Builder.show(AlertDialog.java:802)
E/WindowManager(22019): at
com.phonegap.DroidGap$GapClient.onJsAlert(DroidGap.java:885)
E/WindowManager(22019): at
android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:501)
E/WindowManager(22019): at android.os.Handler.dispatchMessage(Handler.java:99)
E/WindowManager(22019): at android.os.Looper.loop(Looper.java:123)
E/WindowManager(22019): at
android.app.ActivityThread.main(ActivityThread.java:4627)
E/WindowManager(22019): at java.lang.reflect.Method.invokeNative(Native Method)
E/WindowManager(22019): at java.lang.reflect.Method.invoke(Method.java:521)
E/WindowManager(22019): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
E/WindowManager(22019): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
E/WindowManager(22019): at dalvik.system.NativeStart.main(Native Method)

Are you calling an alert dialog from your code?

Simon Mac Donald
http://hi.im/simonmacdonald

Simon MacDonald

unread,
Nov 15, 2011, 10:14:07 AM11/15/11
to phon...@googlegroups.com
Hey Lucy,

It sounds like you are suffering from the issue that the default
intent for taking picture/video does not call onActivityResult
properly. I've run into this on my Samsung phone for audio recording.
This is a vendor bloatware issue and I'm not sure what I can do to fix
it.

Using a separate camera app like you've discovered seems to be the
only work around at the moment.

TehSharpie

unread,
Nov 22, 2011, 6:43:13 AM11/22/11
to phonegap
Hello,

i can bring some light into the dark of my camera functionality.

My Testing Scenario was:
Change things in Adroid Project in Eclipse, run as -> on emulator.
Copy apk to phone, overwriting prior version.
Stopping/Clearing Memory of prior installed version. Now install new
apk. Sometimes even uninstall current version on device.

I could not find any errors, so i ran paranoid. Now I'm deleting apk
inb4 new compile in eclipse, removing prior version manual in
emulator.
On phone uninstalling, prior versions, rebooting the device. Making a
clean install of new apk.
And BOOM it works? Now my Camera works with same code, nothing(!)
changed, with PhoneGap 1.2.0. For Both library and direct Camera.

I could reproduce this and i hope this stays now constant.

Being a SysAdmin in the past, i would consider myself to be able, to
not run in such problems or find them quick. It's frustrating :)
Seems that, my Development Environment got compromised by the latest
google/SDK update Problems, which occured (google it).
More likely: My Android img/Installtion on the Phone does not handle
install correctly or even more likely some installed Apps, which could
influence other App Installations were attacking me :)
Or im not aware of such issues in the Development Process for
Android?!?

I'll stick with this explanation until new problems occur. My Code,
has not changed, and is now working as intended. So no Javascript
errors could have been in the way.

Thanks to Simon for still reviewing my problem.

Regards
TehSharpie

On Nov 15, 4:14 pm, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> Hey Lucy,
>
> It sounds like you are suffering from the issue that the default
> intent for taking picture/video does not call onActivityResult
> properly. I've run into this on my Samsung phone for audio recording.
> This is a vendor bloatware issue and I'm not sure what I can do to fix
> it.
>

> Using a separatecameraapp like you've discovered seems to be the


> only work around at the moment.
>

> Simon Mac Donaldhttp://hi.im/simonmacdonald
>
>
>
>
>
>
>
> On Tue, Nov 8, 2011 at 12:24 PM, LucyJp <kayok...@hotmail.com> wrote:
> > We found that using othercameraapp, getPicture and captureVideo
> > works as expected but using built incameraapp does not work. Does
> > this tell you anything?
>
> > Othercameraapp from market - “Camera360” and “Vignette Demo”


>
> > Any thought?
>
> > Thank you
>
> > On Nov 8, 8:57 am, LucyJp <kayok...@hotmail.com> wrote:
> >> Hi Simon,
>
> >> Please see log athttps://gist.github.com/1347716 (sorry added wrong
> >> url in previous post).
>
> >> Thank you
>
> >> On Nov 8, 8:42 am, LucyJp <kayok...@hotmail.com> wrote:
>
> >> > Hi Simon & Pranav,
>
> >> > I have same issue using Motorola Droid Android 2.2.2/phonegap 1.1.
>

> >> > Hit OK always brings back to thecameraapp and does not call success
> >> > call back. (Thecameraapp provide OK, retake, and cancel buttons.)

> >> > > 2. Link on theapplication, opens thecamera(API used as suggested by


> >> > > you)
> >> > > 3. Photo is taken
> >> > > 4 Since there is no option of saving the file and no way to return
> >> > > back toapplication, I deleted the photo ( After taking photo, it gave
> >> > > me options to delete the photo, take new photo, rename the file name
> >> > > and NO option to update, save as etc)
>
> >> > > Regards,
> >> > > Pranav
>
> >> > > On Nov 7, 7:02 pm, Simon MacDonald <simon.macdon...@gmail.com> wrote:
>

> >> > > > Create a gist onhttps://gist.github.com/asitisaneffective way to


> >> > > > share logs without having to paste it all in an email.
>
> >> > > > Simon Mac Donaldhttp://hi.im/simonmacdonald
>
> >> > > > On Mon, Nov 7, 2011 at 12:33 AM, Pranav <vpra...@gmail.com> wrote:
> >> > > > > Thanks Simon for quick reply.
>

> >> > > > > Shall I grep "D/CameraApp" and send across only theCameralogs or


> >> > > > > attach the entire logs. Also I donotsee the way to attach the file
> >> > > > > here. I have to copy and paste it :)
>
> >> > > > > Regards,
> >> > > > > Pranav
>
> >> > > > > On Nov 7, 9:48 am, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> >> > > > >> Run "adb logcat" so we can see what is going on.
>
> >> > > > >> Simon Mac Donaldhttp://hi.im/simonmacdonald
>
> >> > > > >> On Sun, Nov 6, 2011 at 11:27 PM, Pranav <vpra...@gmail.com> wrote:
> >> > > > >> > Hi Simon,
>
> >> > > > >> > I tried your suggestion but it also didnotwork. After taking photo,

> >> > > > >> >camerais still open and I donotget option to "save" the picture.

> >> > > > >> >> >Cameraopens and I am able to take photo but after photo is taken, the

> >> > > > > For more info on PhoneGap or to download the code go towww.phonegap.com-Hidequotedtext -

Simon MacDonald

unread,
Nov 22, 2011, 10:25:27 AM11/22/11
to phon...@googlegroups.com
TehSharpie glad to hear it is working for you. That is certainly a weird problem.

Simon Mac Donald
http://hi.im/simonmacdonald


Tim Stewart

unread,
May 7, 2012, 3:04:06 AM5/7/12
to phon...@googlegroups.com
In case anyone (like me) comes to this thread with a similar problem, I found the solution on another thread:


Basically, enable  android.permission.WRITE_EXTERNAL_STORAGE, which in my case (using PhoneGap Build service) meant adding the following to config.xml:


Regards
Tim
Reply all
Reply to author
Forward
0 new messages