WARNING: April 12th, 2014: this plugin is in a dormant state. It only supports iOS a little. You're better off not using this. I may pick this up in the future... but for now: look elsewhere.
for iOS, by Eddy Verbruggen
- Description
- Installation 2. Automatically (CLI / Plugman) 2. Manually 2. PhoneGap Build
- Usage
- License
This plugin allows you to use photos from the cameraroll (photo album) of the mobile device.
- For Cordova 3+
- Compatible with Cordova Plugman
- Submitted and waiting for approval at PhoneGap Build (more information)
- You can count the total number of photos and/or videos.
- You can find photos only (videos would likely crash your app).
- You can limit the number of returned photos by passing a
max
parameter. - All methods work without showing the cameraroll to the user. Your app never looses control.
- Supported methods:
find
,count
.
- Work in progress..
CameraRoll is compatible with Cordova Plugman and ready for the PhoneGap 3.0 CLI, here's how it works with the CLI:
$ phonegap local plugin add https://github.com/EddyVerbruggen/CameraRoll-PhoneGap-Plugin.git
or
$ cordova plugin add https://github.com/EddyVerbruggen/CameraRoll-PhoneGap-Plugin.git
don't forget to run this command afterwards:
$ cordova build
1. Add the following xml to your config.xml
:
<!-- for iOS -->
<feature name="CameraRoll">
<param name="ios-package" value="CameraRoll" />
</feature>
<!-- for Android as plugin (deprecated) -->
<plugin name="Calendar" value="nl.xservices.plugins.CameraRoll"/>
<!-- for Android as feature -->
<feature name="CameraRoll">
<param name="android-package" value="nl.xservices.plugins.CameraRoll" />
</feature>
2. Grab a copy of CameraRoll.js, add it to your project and reference it in index.html
:
<script type="text/javascript" src="js/CameraRoll.js"></script>
3. Download the source files for iOS and/or Android and copy them to your project.
iOS: Copy the four .h
and .m
to platforms/ios/<ProjectName>/Plugins
Android: Copy CameraRoll.java
to platforms/android/src/nl/xservices/plugins
(create the folders)
Using CameraRoll with PhoneGap Build requires these simple steps:
1. Add the following xml to your config.xml
to always use the latest version of this plugin:
<gap:plugin name="nl.x-services.plugins.cameraroll" />
or to use this exact version:
<gap:plugin name="nl.x-services.plugins.cameraroll" version="1.0" />
2. Reference the JavaScript code in your index.html
:
<!-- below <script src="phonegap.js"></script> -->
<script src="js/plugins/CameraRoll.js"></script>
Counting the number of photos in the photo library:
// prep some variables
var includePhotos = true;
var includeVideos = false;
window.plugins.cameraRoll.count(includePhotos, includeVideos, showImageCount, cameraRollError);
function showImageCount(count) {
alert("Found " + count + " photos");
}
Find and show max 10 photos from the photo library:
var maxPhotos = 10;
window.plugins.cameraRoll.find(maxPhotos, cameraRollFindResult, cameraRollError);
function cameraRollFindResult(photos) {
var content = '';
for (var i in photos) {
content += '<br/><img src="data:image/png;base64,'+photos[i]+'" style="max-width:240px"/>';
}
document.getElementById("imgContainer").innerHTML = content;
}
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.