Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid, Phonegap, and the Camera: How can I get the picture after my app gets killed?
    primarykey
    data
    text
    <p>EDIT:</p> <p>For those who are seeing this now, we've since solved the problem. See my answers to <a href="https://stackoverflow.com/questions/11544992/taking-a-picture-from-the-camera-fails-20-of-the-time/11546276#11546276">this question</a> and <a href="https://stackoverflow.com/questions/11505127/phonegap-does-not-restore-the-application-after-camera-activity/11544431#11544431">this question</a> for an explanation and possible solution.</p> <p><br></p> <p>Alright, I thought I had this figured out, but I didn't.</p> <p>What's happening is the usual with starting the camera in Android: once you take the picture, the memory requirements cause the system to kill the app that started the camera. My difficulty is that I can't get a hold of the URI for the recently captured image after my app gets killed. I've seen a lot of solutions for this for native Android apps in my searching, but nothing for Phonegap.</p> <p>This is further complicated by the fact that the page that the camera is starting from is not the page that the activity loads into by default. When the app restarts, it wants to restart in the login page of this app, instead of the page that needs the URI of the image data.</p> <p>I got the app to save the last page it was on before it dies, and recall that when it starts. I thought that this would fix the problem, but the camera's callback still doesn't get called. This is probably because even though it's returning to the same page, it's returning to a different instance of that page.</p> <p>Let me show you what I have so far.</p> <p>This is the code that calls the camera:</p> <pre><code> function capturePhoto(){ navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 20, destinationType: Camera.DestinationType.FILE_URI } ); }; function onPhotoURISuccess(imageURI) { //Do some stuff with the image, like save the URI in localStorage } </code></pre> <p>Pretty basic, there's nothing special there. It's just that onPhotoURISuccess() never gets called. Here's how I save and reload the the last page. It's all done in Java in the DroidGap activity:</p> <pre><code> //Save the last page that the user was on @Override public void onSaveInstanceState(Bundle savedState) { super.onSaveInstanceState(savedState); savedState.putString("lastPage", appView.getUrl()); } //Recall the page @Override public void onCreate(Bundle savedState) { super.onCreate(savedState); //The default page is the login page String pageToLoad = "file:///android_asset/www/login.html"; if(savedState != null &amp;&amp; savedState.containsKey("lastPage")) { pageToLoad = savedState.getString("lastPage"); } super.loadUrl(pageToLoad); } </code></pre> <p>So, my thoughts so far have been to somehow get the onActivityResult from the camera in the DroidGap activity, but I'm not sure how that would work, and I would rather not create a Phonegap plugin for it because I'd like to keep the code as cross-platform as possible.</p> <p>The other thought is to somehow tell the camera where to save the picture, relative to the application's directory, from Phonegap. Then, the page that needs the picture could just grab whichever photo is in the specified directory. However, I haven't been able to find a way to do this.</p> <p>Sorry if I overlooked something in my searches and this is a repeat question, and thanks in advance for your help!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload