Adding capture partially solves it.
<input name="photos" type="file" capture="environment" accept="image/*"/>
The only problem now is that user can't select from previously existing photos.
Coming back to this question 6 years later
It seems this is related to Android Memory Management:
- Browser launches camera app
- Camera app becomes foreground, browser becomes background process
- Android, at an O.S level, frees up browser memory
- After the camera is closed, the browser comes to foreground again, triggering a page refresh.
From Android Memory Management:
When users switch between apps, Android keeps apps that are not foreground—that is, not visible to the user or running a foreground service like music playback— in a cache. For example, when a user first launches an app, a process is created for it; but when the user leaves the app, that process does not quit. The system keeps the process cached. If the user later returns to the app, the system reuses the process, thereby making the app switching faster.
If your app has a cached process and it retains resources that it currently does not need, then your app—even while the user is not using it— affects the system's overall performance. As the system runs low on resources like memory, it kills processes in the cache. The system also accounts for processes that hold onto the most memory and can terminate them to free up RAM.
Note: The less memory your app consumes while in the cache, the better its chances are not to be killed and to be able to quickly resume. However, depending on instantanous system requirements, it's possible for cached processes to be terminated at any time no matter their resource utilization.
The reason why capture
works is that it probably keeps the browser process in the foreground?
So I would personally have two buttons, one for choosing existing files, and another for using the camera:
<p>
<label for="cameraFile">Take a picture:</label>
<!-- Set "capture" to "user" to start frontal camera. -->
<input name="cameraFile" type="file" capture="environment" accept="image/*"/>
</p>
<p>
<label for="storageFile">Choose existing file:</label>
<input name="storageFile" type="file" accept="image/*"/>
</p>