Modified: cordova/site/public/docs/en/dev/reference/cordova-plugin-camera/index.html URL: http://svn.apache.org/viewvc/cordova/site/public/docs/en/dev/reference/cordova-plugin-camera/index.html?rev=1752402&r1=1752401&r2=1752402&view=diff ============================================================================== --- cordova/site/public/docs/en/dev/reference/cordova-plugin-camera/index.html (original) +++ cordova/site/public/docs/en/dev/reference/cordova-plugin-camera/index.html Wed Jul 13 11:51:10 2016 @@ -6,12 +6,12 @@ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="format-detection" content="telephone=no"> <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" /> - <meta name="description" content=" "> + <meta name="description" content="Take pictures with the device camera. "> <title> - cordova-plugin-camera - Apache Cordova + Camera - Apache Cordova </title> @@ -732,7 +732,7 @@ <li> <a class="" href="../../reference/cordova-plugin-battery-status/index.html"> - cordova-plugin-battery-status + Battery Status </a> @@ -747,7 +747,7 @@ <li> <a class="this-page" href="../../reference/cordova-plugin-camera/index.html"> - cordova-plugin-camera + Camera </a> <span class="entry-highlight"></span> @@ -764,7 +764,7 @@ <li> <a class="" href="../../reference/cordova-plugin-console/index.html"> - cordova-plugin-console + Console </a> @@ -779,7 +779,7 @@ <li> <a class="" href="../../reference/cordova-plugin-contacts/index.html"> - cordova-plugin-contacts + Contacts </a> @@ -794,7 +794,7 @@ <li> <a class="" href="../../reference/cordova-plugin-device/index.html"> - cordova-plugin-device + Device </a> @@ -809,7 +809,7 @@ <li> <a class="" href="../../reference/cordova-plugin-device-motion/index.html"> - cordova-plugin-device-motion + Device Motion </a> @@ -824,7 +824,7 @@ <li> <a class="" href="../../reference/cordova-plugin-device-orientation/index.html"> - cordova-plugin-device-orientation + Device Orientation </a> @@ -839,7 +839,7 @@ <li> <a class="" href="../../reference/cordova-plugin-dialogs/index.html"> - cordova-plugin-dialogs + Dialogs </a> @@ -854,7 +854,7 @@ <li> <a class="" href="../../reference/cordova-plugin-file/index.html"> - cordova-plugin-file + File </a> @@ -869,7 +869,7 @@ <li> <a class="" href="../../reference/cordova-plugin-file-transfer/index.html"> - cordova-plugin-file-transfer + File Transfer </a> @@ -884,7 +884,7 @@ <li> <a class="" href="../../reference/cordova-plugin-geolocation/index.html"> - cordova-plugin-geolocation + Geolocation </a> @@ -899,7 +899,7 @@ <li> <a class="" href="../../reference/cordova-plugin-globalization/index.html"> - cordova-plugin-globalization + Globalization </a> @@ -914,7 +914,7 @@ <li> <a class="" href="../../reference/cordova-plugin-inappbrowser/index.html"> - cordova-plugin-inappbrowser + Inappbrowser </a> @@ -929,7 +929,7 @@ <li> <a class="" href="../../reference/cordova-plugin-media/index.html"> - cordova-plugin-media + Media </a> @@ -944,7 +944,7 @@ <li> <a class="" href="../../reference/cordova-plugin-media-capture/index.html"> - cordova-plugin-media-capture + Media Capture </a> @@ -959,7 +959,7 @@ <li> <a class="" href="../../reference/cordova-plugin-network-information/index.html"> - cordova-plugin-network-information + Network Information </a> @@ -974,7 +974,7 @@ <li> <a class="" href="../../reference/cordova-plugin-splashscreen/index.html"> - cordova-plugin-splashscreen + Splashscreen </a> @@ -989,7 +989,7 @@ <li> <a class="" href="../../reference/cordova-plugin-vibration/index.html"> - cordova-plugin-vibration + Vibration </a> @@ -1004,7 +1004,7 @@ <li> <a class="" href="../../reference/cordova-plugin-statusbar/index.html"> - cordova-plugin-statusbar + Statusbar </a> @@ -1019,7 +1019,7 @@ <li> <a class="" href="../../reference/cordova-plugin-whitelist/index.html"> - cordova-plugin-whitelist + Whitelist </a> @@ -1034,7 +1034,7 @@ <li> <a class="" href="../../reference/cordova-plugin-legacy-whitelist/index.html"> - cordova-plugin-legacy-whitelist + Legacy Whitelist </a> @@ -1388,7 +1388,7 @@ <li> <a class="" href="../../reference/cordova-plugin-battery-status/index.html"> - cordova-plugin-battery-status + Battery Status </a> </li> @@ -1397,7 +1397,7 @@ <li> <a class="this-page" href="../../reference/cordova-plugin-camera/index.html"> - cordova-plugin-camera + Camera </a> </li> @@ -1406,7 +1406,7 @@ <li> <a class="" href="../../reference/cordova-plugin-console/index.html"> - cordova-plugin-console + Console </a> </li> @@ -1415,7 +1415,7 @@ <li> <a class="" href="../../reference/cordova-plugin-contacts/index.html"> - cordova-plugin-contacts + Contacts </a> </li> @@ -1424,7 +1424,7 @@ <li> <a class="" href="../../reference/cordova-plugin-device/index.html"> - cordova-plugin-device + Device </a> </li> @@ -1433,7 +1433,7 @@ <li> <a class="" href="../../reference/cordova-plugin-device-motion/index.html"> - cordova-plugin-device-motion + Device Motion </a> </li> @@ -1442,7 +1442,7 @@ <li> <a class="" href="../../reference/cordova-plugin-device-orientation/index.html"> - cordova-plugin-device-orientation + Device Orientation </a> </li> @@ -1451,7 +1451,7 @@ <li> <a class="" href="../../reference/cordova-plugin-dialogs/index.html"> - cordova-plugin-dialogs + Dialogs </a> </li> @@ -1460,7 +1460,7 @@ <li> <a class="" href="../../reference/cordova-plugin-file/index.html"> - cordova-plugin-file + File </a> </li> @@ -1469,7 +1469,7 @@ <li> <a class="" href="../../reference/cordova-plugin-file-transfer/index.html"> - cordova-plugin-file-transfer + File Transfer </a> </li> @@ -1478,7 +1478,7 @@ <li> <a class="" href="../../reference/cordova-plugin-geolocation/index.html"> - cordova-plugin-geolocation + Geolocation </a> </li> @@ -1487,7 +1487,7 @@ <li> <a class="" href="../../reference/cordova-plugin-globalization/index.html"> - cordova-plugin-globalization + Globalization </a> </li> @@ -1496,7 +1496,7 @@ <li> <a class="" href="../../reference/cordova-plugin-inappbrowser/index.html"> - cordova-plugin-inappbrowser + Inappbrowser </a> </li> @@ -1505,7 +1505,7 @@ <li> <a class="" href="../../reference/cordova-plugin-media/index.html"> - cordova-plugin-media + Media </a> </li> @@ -1514,7 +1514,7 @@ <li> <a class="" href="../../reference/cordova-plugin-media-capture/index.html"> - cordova-plugin-media-capture + Media Capture </a> </li> @@ -1523,7 +1523,7 @@ <li> <a class="" href="../../reference/cordova-plugin-network-information/index.html"> - cordova-plugin-network-information + Network Information </a> </li> @@ -1532,7 +1532,7 @@ <li> <a class="" href="../../reference/cordova-plugin-splashscreen/index.html"> - cordova-plugin-splashscreen + Splashscreen </a> </li> @@ -1541,7 +1541,7 @@ <li> <a class="" href="../../reference/cordova-plugin-vibration/index.html"> - cordova-plugin-vibration + Vibration </a> </li> @@ -1550,7 +1550,7 @@ <li> <a class="" href="../../reference/cordova-plugin-statusbar/index.html"> - cordova-plugin-statusbar + Statusbar </a> </li> @@ -1559,7 +1559,7 @@ <li> <a class="" href="../../reference/cordova-plugin-whitelist/index.html"> - cordova-plugin-whitelist + Whitelist </a> </li> @@ -1568,7 +1568,7 @@ <li> <a class="" href="../../reference/cordova-plugin-legacy-whitelist/index.html"> - cordova-plugin-legacy-whitelist + Legacy Whitelist </a> </li> @@ -2688,7 +2688,25 @@ # under the License. --> -<p><a href="https://travis-ci.org/apache/cordova-plugin-camera"><img src="https://travis-ci.org/apache/cordova-plugin-camera.svg?branch=master" alt="Build Status"></a></p> +<table><thead> +<tr> +<th style="text-align: center">Android</th> +<th style="text-align: center">iOS</th> +<th style="text-align: center">Windows 8.1 Store</th> +<th style="text-align: center">Windows 8.1 Phone</th> +<th style="text-align: center">Windows 10 Store</th> +<th style="text-align: center">Travis CI</th> +</tr> +</thead><tbody> +<tr> +<td style="text-align: center"><a href="http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-camera/"><img src="http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-camera" alt="Build Status"></a></td> +<td style="text-align: center"><a href="http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-camera/"><img src="http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-camera" alt="Build Status"></a></td> +<td style="text-align: center"><a href="http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-camera/"><img src="http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-camera" alt="Build Status"></a></td> +<td style="text-align: center"><a href="http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-camera/"><img src="http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-camera" alt="Build Status"></a></td> +<td style="text-align: center"><a href="http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-camera/"><img src="http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-camera" alt="Build Status"></a></td> +<td style="text-align: center"><a href="https://travis-ci.org/apache/cordova-plugin-camera"><img src="https://travis-ci.org/apache/cordova-plugin-camera.svg?branch=master" alt="Build Status"></a></td> +</tr> +</tbody></table> <h1>cordova-plugin-camera</h1> @@ -2734,7 +2752,7 @@ Documentation consists of template and A <hr> -<h1>API Reference</h1> +<h1>API Reference <a name="reference"></a></h1> <ul> <li><p><a href="#module_camera">camera</a></p> @@ -3483,6 +3501,184 @@ via Zune does not work, and triggers an <li><p>Ignores the <code>mediaType</code> property of <code>cameraOptions</code> as the Windows Phone SDK does not provide a way to choose videos from PHOTOLIBRARY.</p></li> </ul> +<h2>Sample: Take Pictures, Select Pictures from the Picture Library, and Get Thumbnails <a name="sample"></a></h2> + +<p>The Camera plugin allows you to do things like open the device's Camera app and take a picture, or open the file picker and select one. The code snippets in this section demonstrate different tasks including:</p> + +<ul> +<li>Open the Camera app and <a href="#takePicture">take a Picture</a></li> +<li>Take a picture and <a href="#getThumbnails">return thumbnails</a> (resized picture)</li> +<li>Take a picture and <a href="#convert">generate a FileEntry object</a></li> +<li><a href="#selectFile">Select a file</a> from the picture library</li> +<li>Select a JPEG image and <a href="#getFileThumbnails">return thumbnails</a> (resized image)</li> +<li>Select an image and <a href="#convert">generate a FileEntry object</a></li> +</ul> + +<h2>Take a Picture <a name="takePicture"></a></h2> + +<p>Before you can take a picture, you need to set some Camera plugin options to pass into the Camera plugin's <code>getPicture</code> function. Here is a common set of recommendations. In this example, you create the object that you will use for the Camera options, and set the <code>sourceType</code> dynamically to support both the Camera app and the file picker.</p> +<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">setOptions</span><span class="p">(</span><span class="nx">srcType</span><span class="p">)</span> <span class="p">{</span> + <span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="p">{</span> + <span class="c1">// Some common settings are 20, 50, and 100</span> + <span class="na">quality</span><span class="p">:</span> <span class="mi">50</span><span class="p">,</span> + <span class="na">destinationType</span><span class="p">:</span> <span class="nx">Camera</span><span class="p">.</span><span class="nx">DestinationType</span><span class="p">.</span><span class="nx">FILE_URI</span><span class="p">,</span> + <span class="c1">// In this app, dynamically set the picture source, Camera or photo gallery</span> + <span class="na">sourceType</span><span class="p">:</span> <span class="nx">srcType</span><span class="p">,</span> + <span class="na">encodingType</span><span class="p">:</span> <span class="nx">Camera</span><span class="p">.</span><span class="nx">EncodingType</span><span class="p">.</span><span class="nx">JPEG</span><span class="p">,</span> + <span class="na">mediaType</span><span class="p">:</span> <span class="nx">Camera</span><span class="p">.</span><span class="nx">MediaType</span><span class="p">.</span><span class="nx">PICTURE</span><span class="p">,</span> + <span class="na">allowEdit</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span> + <span class="na">correctOrientation</span><span class="p">:</span> <span class="kc">true</span> <span class="c1">//Corrects Android orientation quirks</span> + <span class="p">}</span> + <span class="k">return</span> <span class="nx">options</span><span class="p">;</span> +<span class="p">}</span> +</code></pre></div> +<p>Typically, you want to use a FILE<em>URI instead of a DATA</em>URL to avoid most memory issues. JPEG is the recommended encoding type for Android.</p> + +<p>You take a picture by passing in the options object to <code>getPicture</code>, which takes a CameraOptions object as the third argument. When you call <code>setOptions</code>, pass <code>Camera.PictureSourceType.CAMERA</code> as the picture source.</p> +<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">openCamera</span><span class="p">(</span><span class="nx">selection</span><span class="p">)</span> <span class="p">{</span> + + <span class="kd">var</span> <span class="nx">srcType</span> <span class="o">=</span> <span class="nx">Camera</span><span class="p">.</span><span class="nx">PictureSourceType</span><span class="p">.</span><span class="nx">CAMERA</span><span class="p">;</span> + <span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="nx">setOptions</span><span class="p">(</span><span class="nx">srcType</span><span class="p">);</span> + <span class="kd">var</span> <span class="nx">func</span> <span class="o">=</span> <span class="nx">createNewFileEntry</span><span class="p">;</span> + + <span class="nx">navigator</span><span class="p">.</span><span class="nx">camera</span><span class="p">.</span><span class="nx">getPicture</span><span class="p">(</span><span class="kd">function</span> <span class="nx">cameraSuccess</span><span class="p">(</span><span class="nx">imageUri</span><span class="p">)</span> <span class="p">{</span> + + <span class="nx">displayImage</span><span class="p">(</span><span class="nx">imageUri</span><span class="p">);</span> + <span class="c1">// You may choose to copy the picture, save it somewhere, or upload.</span> + <span class="nx">func</span><span class="p">(</span><span class="nx">imageUri</span><span class="p">);</span> + + <span class="p">},</span> <span class="kd">function</span> <span class="nx">cameraError</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span> + <span class="nx">console</span><span class="p">.</span><span class="nx">debug</span><span class="p">(</span><span class="s2">"Unable to obtain picture: "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">,</span> <span class="s2">"app"</span><span class="p">);</span> + + <span class="p">},</span> <span class="nx">options</span><span class="p">);</span> +<span class="p">}</span> +</code></pre></div> +<p>Once you take the picture, you can display it or do something else. In this example, call the app's <code>displayImage</code> function from the preceding code.</p> +<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">displayImage</span><span class="p">(</span><span class="nx">imgUri</span><span class="p">)</span> <span class="p">{</span> + + <span class="kd">var</span> <span class="nx">elem</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">'imageFile'</span><span class="p">);</span> + <span class="nx">elem</span><span class="p">.</span><span class="nx">src</span> <span class="o">=</span> <span class="nx">imgUri</span><span class="p">;</span> +<span class="p">}</span> +</code></pre></div> +<p>To display the image on some platforms, you might need to include the main part of the URI in the Content-Security-Policy <code><meta></code> element in index.html. For example, on Windows 10, you can include <code>ms-appdata:</code> in your <code><meta></code> element. Here is an example.</p> +<div class="highlight"><pre><code class="language-html" data-lang="html"><span class="nt"><meta</span> <span class="na">http-equiv=</span><span class="s">"Content-Security-Policy"</span> <span class="na">content=</span><span class="s">"default-src 'self' data: gap: ms-appdata: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *"</span><span class="nt">></span> +</code></pre></div> +<h2>Take a Picture and Return Thumbnails (Resize the Picture) <a name="getThumbnails"></a></h2> + +<p>To get smaller images, you can return a resized image by passing both <code>targetHeight</code> and <code>targetWidth</code> values with your CameraOptions object. In this example, you resize the returned image to fit in a 100px by 100px box (the aspect ratio is maintained, so 100px is either the height or width, whichever is greater in the source).</p> +<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">openCamera</span><span class="p">(</span><span class="nx">selection</span><span class="p">)</span> <span class="p">{</span> + + <span class="kd">var</span> <span class="nx">srcType</span> <span class="o">=</span> <span class="nx">Camera</span><span class="p">.</span><span class="nx">PictureSourceType</span><span class="p">.</span><span class="nx">CAMERA</span><span class="p">;</span> + <span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="nx">setOptions</span><span class="p">(</span><span class="nx">srcType</span><span class="p">);</span> + <span class="kd">var</span> <span class="nx">func</span> <span class="o">=</span> <span class="nx">createNewFileEntry</span><span class="p">;</span> + + <span class="k">if</span> <span class="p">(</span><span class="nx">selection</span> <span class="o">==</span> <span class="s2">"camera-thmb"</span><span class="p">)</span> <span class="p">{</span> + <span class="nx">options</span><span class="p">.</span><span class="nx">targetHeight</span> <span class="o">=</span> <span class="mi">100</span><span class="p">;</span> + <span class="nx">options</span><span class="p">.</span><span class="nx">targetWidth</span> <span class="o">=</span> <span class="mi">100</span><span class="p">;</span> + <span class="p">}</span> + + <span class="nx">navigator</span><span class="p">.</span><span class="nx">camera</span><span class="p">.</span><span class="nx">getPicture</span><span class="p">(</span><span class="kd">function</span> <span class="nx">cameraSuccess</span><span class="p">(</span><span class="nx">imageUri</span><span class="p">)</span> <span class="p">{</span> + + <span class="c1">// Do something</span> + + <span class="p">},</span> <span class="kd">function</span> <span class="nx">cameraError</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span> + <span class="nx">console</span><span class="p">.</span><span class="nx">debug</span><span class="p">(</span><span class="s2">"Unable to obtain picture: "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">,</span> <span class="s2">"app"</span><span class="p">);</span> + + <span class="p">},</span> <span class="nx">options</span><span class="p">);</span> +<span class="p">}</span> +</code></pre></div> +<h2>Select a File from the Picture Library <a name="selectFile"></a></h2> + +<p>When selecting a file using the file picker, you also need to set the CameraOptions object. In this example, set the <code>sourceType</code> to <code>Camera.PictureSourceType.SAVEDPHOTOALBUM</code>. To open the file picker, call <code>getPicture</code> just as you did in the previous example, passing in the success and error callbacks along with CameraOptions object.</p> +<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">openFilePicker</span><span class="p">(</span><span class="nx">selection</span><span class="p">)</span> <span class="p">{</span> + + <span class="kd">var</span> <span class="nx">srcType</span> <span class="o">=</span> <span class="nx">Camera</span><span class="p">.</span><span class="nx">PictureSourceType</span><span class="p">.</span><span class="nx">SAVEDPHOTOALBUM</span><span class="p">;</span> + <span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="nx">setOptions</span><span class="p">(</span><span class="nx">srcType</span><span class="p">);</span> + <span class="kd">var</span> <span class="nx">func</span> <span class="o">=</span> <span class="nx">createNewFileEntry</span><span class="p">;</span> + + <span class="nx">navigator</span><span class="p">.</span><span class="nx">camera</span><span class="p">.</span><span class="nx">getPicture</span><span class="p">(</span><span class="kd">function</span> <span class="nx">cameraSuccess</span><span class="p">(</span><span class="nx">imageUri</span><span class="p">)</span> <span class="p">{</span> + + <span class="c1">// Do something</span> + + <span class="p">},</span> <span class="kd">function</span> <span class="nx">cameraError</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span> + <span class="nx">console</span><span class="p">.</span><span class="nx">debug</span><span class="p">(</span><span class="s2">"Unable to obtain picture: "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">,</span> <span class="s2">"app"</span><span class="p">);</span> + + <span class="p">},</span> <span class="nx">options</span><span class="p">);</span> +<span class="p">}</span> +</code></pre></div> +<h2>Select an Image and Return Thumbnails (resized images) <a name="getFileThumbnails"></a></h2> + +<p>Resizing a file selected with the file picker works just like resizing using the Camera app; set the <code>targetHeight</code> and <code>targetWidth</code> options.</p> +<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">openFilePicker</span><span class="p">(</span><span class="nx">selection</span><span class="p">)</span> <span class="p">{</span> + + <span class="kd">var</span> <span class="nx">srcType</span> <span class="o">=</span> <span class="nx">Camera</span><span class="p">.</span><span class="nx">PictureSourceType</span><span class="p">.</span><span class="nx">SAVEDPHOTOALBUM</span><span class="p">;</span> + <span class="kd">var</span> <span class="nx">options</span> <span class="o">=</span> <span class="nx">setOptions</span><span class="p">(</span><span class="nx">srcType</span><span class="p">);</span> + <span class="kd">var</span> <span class="nx">func</span> <span class="o">=</span> <span class="nx">createNewFileEntry</span><span class="p">;</span> + + <span class="k">if</span> <span class="p">(</span><span class="nx">selection</span> <span class="o">==</span> <span class="s2">"picker-thmb"</span><span class="p">)</span> <span class="p">{</span> + <span class="c1">// To downscale a selected image,</span> + <span class="c1">// Camera.EncodingType (e.g., JPEG) must match the selected image type.</span> + <span class="nx">options</span><span class="p">.</span><span class="nx">targetHeight</span> <span class="o">=</span> <span class="mi">100</span><span class="p">;</span> + <span class="nx">options</span><span class="p">.</span><span class="nx">targetWidth</span> <span class="o">=</span> <span class="mi">100</span><span class="p">;</span> + <span class="p">}</span> + + <span class="nx">navigator</span><span class="p">.</span><span class="nx">camera</span><span class="p">.</span><span class="nx">getPicture</span><span class="p">(</span><span class="kd">function</span> <span class="nx">cameraSuccess</span><span class="p">(</span><span class="nx">imageUri</span><span class="p">)</span> <span class="p">{</span> + + <span class="c1">// Do something with image</span> + + <span class="p">},</span> <span class="kd">function</span> <span class="nx">cameraError</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span> + <span class="nx">console</span><span class="p">.</span><span class="nx">debug</span><span class="p">(</span><span class="s2">"Unable to obtain picture: "</span> <span class="o">+</span> <span class="nx">error</span><span class="p">,</span> <span class="s2">"app"</span><span class="p">);</span> + + <span class="p">},</span> <span class="nx">options</span><span class="p">);</span> +<span class="p">}</span> +</code></pre></div> +<h2>Take a picture and get a FileEntry Object <a name="convert"></a></h2> + +<p>If you want to do something like copy the image to another location, or upload it somewhere using the FileTransfer plugin, you need to get a FileEntry object for the returned picture. To do that, call <code>window.resolveLocalFileSystemURL</code> on the file URI returned by the Camera app. If you need to use a FileEntry object, set the <code>destinationType</code> to <code>Camera.DestinationType.FILE_URI</code> in your CameraOptions object (this is also the default value).</p> + +<blockquote> +<p><em>Note</em> You need the <a href="https://www.npmjs.com/package/cordova-plugin-file">File plugin</a> to call <code>window.resolveLocalFileSystemURL</code>.</p> +</blockquote> + +<p>Here is the call to <code>window.resolveLocalFileSystemURL</code>. The image URI is passed to this function from the success callback of <code>getPicture</code>. The success handler of <code>resolveLocalFileSystemURL</code> receives the FileEntry object.</p> +<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">getFileEntry</span><span class="p">(</span><span class="nx">imgUri</span><span class="p">)</span> <span class="p">{</span> + <span class="nb">window</span><span class="p">.</span><span class="nx">resolveLocalFileSystemURL</span><span class="p">(</span><span class="nx">imgUri</span><span class="p">,</span> <span class="kd">function</span> <span class="nx">success</span><span class="p">(</span><span class="nx">fileEntry</span><span class="p">)</span> <span class="p">{</span> + + <span class="c1">// Do something with the FileEntry object, like write to it, upload it, etc.</span> + <span class="c1">// writeFile(fileEntry, imgUri);</span> + <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"got file: "</span> <span class="o">+</span> <span class="nx">fileEntry</span><span class="p">.</span><span class="nx">fullPath</span><span class="p">);</span> + <span class="c1">// displayFileData(fileEntry.nativeURL, "Native URL");</span> + + <span class="p">},</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="c1">// If don't get the FileEntry (which may happen when testing</span> + <span class="c1">// on some emulators), copy to a new FileEntry.</span> + <span class="nx">createNewFileEntry</span><span class="p">(</span><span class="nx">imgUri</span><span class="p">);</span> + <span class="p">});</span> +<span class="p">}</span> +</code></pre></div> +<p>In the example shown in the preceding code, you call the app's <code>createNewFileEntry</code> function if you don't get a valid FileEntry object. The image URI returned from the Camera app should result in a valid FileEntry, but platform behavior on some emulators may be different for files returned from the file picker.</p> + +<blockquote> +<p><em>Note</em> To see an example of writing to a FileEntry, see the <a href="https://www.npmjs.com/package/cordova-plugin-file">File plugin README</a>.</p> +</blockquote> + +<p>The code shown here creates a file in your app's cache (in sandboxed storage) named <code>tempFile.jpeg</code>. With the new FileEntry object, you can copy the image to the file or do something else like upload it.</p> +<div class="highlight"><pre><code class="language-js" data-lang="js"><span class="kd">function</span> <span class="nx">createNewFileEntry</span><span class="p">(</span><span class="nx">imgUri</span><span class="p">)</span> <span class="p">{</span> + <span class="nb">window</span><span class="p">.</span><span class="nx">resolveLocalFileSystemURL</span><span class="p">(</span><span class="nx">cordova</span><span class="p">.</span><span class="nx">file</span><span class="p">.</span><span class="nx">cacheDirectory</span><span class="p">,</span> <span class="kd">function</span> <span class="nx">success</span><span class="p">(</span><span class="nx">dirEntry</span><span class="p">)</span> <span class="p">{</span> + + <span class="c1">// JPEG file</span> + <span class="nx">dirEntry</span><span class="p">.</span><span class="nx">getFile</span><span class="p">(</span><span class="s2">"tempFile.jpeg"</span><span class="p">,</span> <span class="p">{</span> <span class="na">create</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span> <span class="na">exclusive</span><span class="p">:</span> <span class="kc">false</span> <span class="p">},</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">fileEntry</span><span class="p">)</span> <span class="p">{</span> + + <span class="c1">// Do something with it, like write to it, upload it, etc.</span> + <span class="c1">// writeFile(fileEntry, imgUri);</span> + <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">"got file: "</span> <span class="o">+</span> <span class="nx">fileEntry</span><span class="p">.</span><span class="nx">fullPath</span><span class="p">);</span> + <span class="c1">// displayFileData(fileEntry.fullPath, "File copied to");</span> + + <span class="p">},</span> <span class="nx">onErrorCreateFile</span><span class="p">);</span> + + <span class="p">},</span> <span class="nx">onErrorResolveUrl</span><span class="p">);</span> +<span class="p">}</span> +</code></pre></div> </div> </div>
Modified: cordova/site/public/docs/en/dev/reference/cordova-plugin-console/index.html URL: http://svn.apache.org/viewvc/cordova/site/public/docs/en/dev/reference/cordova-plugin-console/index.html?rev=1752402&r1=1752401&r2=1752402&view=diff ============================================================================== --- cordova/site/public/docs/en/dev/reference/cordova-plugin-console/index.html (original) +++ cordova/site/public/docs/en/dev/reference/cordova-plugin-console/index.html Wed Jul 13 11:51:10 2016 @@ -6,12 +6,12 @@ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="format-detection" content="telephone=no"> <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" /> - <meta name="description" content=" "> + <meta name="description" content="Get JavaScript logs in your native logs. "> <title> - cordova-plugin-console - Apache Cordova + Console - Apache Cordova </title> @@ -732,7 +732,7 @@ <li> <a class="" href="../../reference/cordova-plugin-battery-status/index.html"> - cordova-plugin-battery-status + Battery Status </a> @@ -747,7 +747,7 @@ <li> <a class="" href="../../reference/cordova-plugin-camera/index.html"> - cordova-plugin-camera + Camera </a> @@ -762,7 +762,7 @@ <li> <a class="this-page" href="../../reference/cordova-plugin-console/index.html"> - cordova-plugin-console + Console </a> <span class="entry-highlight"></span> @@ -779,7 +779,7 @@ <li> <a class="" href="../../reference/cordova-plugin-contacts/index.html"> - cordova-plugin-contacts + Contacts </a> @@ -794,7 +794,7 @@ <li> <a class="" href="../../reference/cordova-plugin-device/index.html"> - cordova-plugin-device + Device </a> @@ -809,7 +809,7 @@ <li> <a class="" href="../../reference/cordova-plugin-device-motion/index.html"> - cordova-plugin-device-motion + Device Motion </a> @@ -824,7 +824,7 @@ <li> <a class="" href="../../reference/cordova-plugin-device-orientation/index.html"> - cordova-plugin-device-orientation + Device Orientation </a> @@ -839,7 +839,7 @@ <li> <a class="" href="../../reference/cordova-plugin-dialogs/index.html"> - cordova-plugin-dialogs + Dialogs </a> @@ -854,7 +854,7 @@ <li> <a class="" href="../../reference/cordova-plugin-file/index.html"> - cordova-plugin-file + File </a> @@ -869,7 +869,7 @@ <li> <a class="" href="../../reference/cordova-plugin-file-transfer/index.html"> - cordova-plugin-file-transfer + File Transfer </a> @@ -884,7 +884,7 @@ <li> <a class="" href="../../reference/cordova-plugin-geolocation/index.html"> - cordova-plugin-geolocation + Geolocation </a> @@ -899,7 +899,7 @@ <li> <a class="" href="../../reference/cordova-plugin-globalization/index.html"> - cordova-plugin-globalization + Globalization </a> @@ -914,7 +914,7 @@ <li> <a class="" href="../../reference/cordova-plugin-inappbrowser/index.html"> - cordova-plugin-inappbrowser + Inappbrowser </a> @@ -929,7 +929,7 @@ <li> <a class="" href="../../reference/cordova-plugin-media/index.html"> - cordova-plugin-media + Media </a> @@ -944,7 +944,7 @@ <li> <a class="" href="../../reference/cordova-plugin-media-capture/index.html"> - cordova-plugin-media-capture + Media Capture </a> @@ -959,7 +959,7 @@ <li> <a class="" href="../../reference/cordova-plugin-network-information/index.html"> - cordova-plugin-network-information + Network Information </a> @@ -974,7 +974,7 @@ <li> <a class="" href="../../reference/cordova-plugin-splashscreen/index.html"> - cordova-plugin-splashscreen + Splashscreen </a> @@ -989,7 +989,7 @@ <li> <a class="" href="../../reference/cordova-plugin-vibration/index.html"> - cordova-plugin-vibration + Vibration </a> @@ -1004,7 +1004,7 @@ <li> <a class="" href="../../reference/cordova-plugin-statusbar/index.html"> - cordova-plugin-statusbar + Statusbar </a> @@ -1019,7 +1019,7 @@ <li> <a class="" href="../../reference/cordova-plugin-whitelist/index.html"> - cordova-plugin-whitelist + Whitelist </a> @@ -1034,7 +1034,7 @@ <li> <a class="" href="../../reference/cordova-plugin-legacy-whitelist/index.html"> - cordova-plugin-legacy-whitelist + Legacy Whitelist </a> @@ -1388,7 +1388,7 @@ <li> <a class="" href="../../reference/cordova-plugin-battery-status/index.html"> - cordova-plugin-battery-status + Battery Status </a> </li> @@ -1397,7 +1397,7 @@ <li> <a class="" href="../../reference/cordova-plugin-camera/index.html"> - cordova-plugin-camera + Camera </a> </li> @@ -1406,7 +1406,7 @@ <li> <a class="this-page" href="../../reference/cordova-plugin-console/index.html"> - cordova-plugin-console + Console </a> </li> @@ -1415,7 +1415,7 @@ <li> <a class="" href="../../reference/cordova-plugin-contacts/index.html"> - cordova-plugin-contacts + Contacts </a> </li> @@ -1424,7 +1424,7 @@ <li> <a class="" href="../../reference/cordova-plugin-device/index.html"> - cordova-plugin-device + Device </a> </li> @@ -1433,7 +1433,7 @@ <li> <a class="" href="../../reference/cordova-plugin-device-motion/index.html"> - cordova-plugin-device-motion + Device Motion </a> </li> @@ -1442,7 +1442,7 @@ <li> <a class="" href="../../reference/cordova-plugin-device-orientation/index.html"> - cordova-plugin-device-orientation + Device Orientation </a> </li> @@ -1451,7 +1451,7 @@ <li> <a class="" href="../../reference/cordova-plugin-dialogs/index.html"> - cordova-plugin-dialogs + Dialogs </a> </li> @@ -1460,7 +1460,7 @@ <li> <a class="" href="../../reference/cordova-plugin-file/index.html"> - cordova-plugin-file + File </a> </li> @@ -1469,7 +1469,7 @@ <li> <a class="" href="../../reference/cordova-plugin-file-transfer/index.html"> - cordova-plugin-file-transfer + File Transfer </a> </li> @@ -1478,7 +1478,7 @@ <li> <a class="" href="../../reference/cordova-plugin-geolocation/index.html"> - cordova-plugin-geolocation + Geolocation </a> </li> @@ -1487,7 +1487,7 @@ <li> <a class="" href="../../reference/cordova-plugin-globalization/index.html"> - cordova-plugin-globalization + Globalization </a> </li> @@ -1496,7 +1496,7 @@ <li> <a class="" href="../../reference/cordova-plugin-inappbrowser/index.html"> - cordova-plugin-inappbrowser + Inappbrowser </a> </li> @@ -1505,7 +1505,7 @@ <li> <a class="" href="../../reference/cordova-plugin-media/index.html"> - cordova-plugin-media + Media </a> </li> @@ -1514,7 +1514,7 @@ <li> <a class="" href="../../reference/cordova-plugin-media-capture/index.html"> - cordova-plugin-media-capture + Media Capture </a> </li> @@ -1523,7 +1523,7 @@ <li> <a class="" href="../../reference/cordova-plugin-network-information/index.html"> - cordova-plugin-network-information + Network Information </a> </li> @@ -1532,7 +1532,7 @@ <li> <a class="" href="../../reference/cordova-plugin-splashscreen/index.html"> - cordova-plugin-splashscreen + Splashscreen </a> </li> @@ -1541,7 +1541,7 @@ <li> <a class="" href="../../reference/cordova-plugin-vibration/index.html"> - cordova-plugin-vibration + Vibration </a> </li> @@ -1550,7 +1550,7 @@ <li> <a class="" href="../../reference/cordova-plugin-statusbar/index.html"> - cordova-plugin-statusbar + Statusbar </a> </li> @@ -1559,7 +1559,7 @@ <li> <a class="" href="../../reference/cordova-plugin-whitelist/index.html"> - cordova-plugin-whitelist + Whitelist </a> </li> @@ -1568,7 +1568,7 @@ <li> <a class="" href="../../reference/cordova-plugin-legacy-whitelist/index.html"> - cordova-plugin-legacy-whitelist + Legacy Whitelist </a> </li> @@ -2688,7 +2688,25 @@ # under the License. --> -<p><a href="https://travis-ci.org/apache/cordova-plugin-console"><img src="https://travis-ci.org/apache/cordova-plugin-console.svg?branch=master" alt="Build Status"></a></p> +<table><thead> +<tr> +<th style="text-align: center">Android</th> +<th style="text-align: center">iOS</th> +<th style="text-align: center">Windows 8.1 Store</th> +<th style="text-align: center">Windows 8.1 Phone</th> +<th style="text-align: center">Windows 10 Store</th> +<th style="text-align: center">Travis CI</th> +</tr> +</thead><tbody> +<tr> +<td style="text-align: center"><a href="http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-console/"><img src="http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android,PLUGIN=cordova-plugin-console" alt="Build Status"></a></td> +<td style="text-align: center"><a href="http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-console/"><img src="http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios,PLUGIN=cordova-plugin-console" alt="Build Status"></a></td> +<td style="text-align: center"><a href="http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-console/"><img src="http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-store,PLUGIN=cordova-plugin-console" alt="Build Status"></a></td> +<td style="text-align: center"><a href="http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-console/"><img src="http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-8.1-phone,PLUGIN=cordova-plugin-console" alt="Build Status"></a></td> +<td style="text-align: center"><a href="http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-console/"><img src="http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-console" alt="Build Status"></a></td> +<td style="text-align: center"><a href="https://travis-ci.org/apache/cordova-plugin-console"><img src="https://travis-ci.org/apache/cordova-plugin-console.svg?branch=master" alt="Build Status"></a></td> +</tr> +</tbody></table> <h1>cordova-plugin-console</h1> --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org