phonegap学习笔记1——创建工程 使用插件
来源:互联网 发布:无尽之剑3宝石数据修改 编辑:程序博客网 时间:2024/05/01 11:26
cordova create hello com.zyt.hello "hello"
cd hello
cd plugins
cordova plugin add org.apache,cordova.camera("org.apache,cordova.camera"区分大小写)
至此工程成功创建,插件文件成功添加到了plugins目录下
修改androidmanifest.xml文件,添加权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
修改config.xml添加插件
<plugin name="Camera" value="org.apache.cordova.camera" />
value的值根据\hello\plugins\org.apache.cordova.camera目录下的plugin.xml中id="org.apache.cordova.camera"来定。
至此可以在网页文件中调用摄像头了,官方demo:
<!DOCTYPE html>
<html>
<head>
<title>Capture Photo</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for device API libraries to load
//
document.addEventListener("deviceready",onDeviceReady,false);
// device APIs are available
//
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageData) {
// Uncomment to view the base64-encoded image data
// console.log(imageData);
// Get image handle
//
var smallImage = document.getElementById('smallImage');
// Unhide image elements
//
smallImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
//
smallImage.src = "data:image/jpeg;base64," + imageData;
}
// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
// Uncomment to view the image file URI
// console.log(imageURI);
// Get image handle
//
var largeImage = document.getElementById('largeImage');
// Unhide image elements
//
largeImage.style.display = 'block';
// Show the captured photo
// The inline CSS rules are used to resize the image
//
largeImage.src = imageURI;
}
// A button will call this function
//
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType: destinationType.DATA_URL });
}
// A button will call this function
//
function capturePhotoEdit() {
// Take picture using device camera, allow edit, and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL });
}
// A button will call this function
//
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}
// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}
</script>
</head>
<body>
<button onclick="capturePhoto();">Capture Photo</button> <br>
<button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
<button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
<img style="display:none;" id="largeImage" src="" />
</body>
</html>
- phonegap学习笔记1——创建工程 使用插件
- 学习使用PhoneGap笔记
- PhoneGap/Cordova学习笔记--3.初次使用Cordova插件
- phoneGap学习笔记——android+phoneGap环境搭建
- PhoneGap 创建XCode工程
- phoneGap工程的创建
- phonegap安装 创建工程
- Maven学习笔记(二)——创建Maven工程&Maven命令的使用
- ios PhoneGap的使用(一、工程的创建)
- Maven学习笔记(八)——创建聚合工程
- Eclipse插件开发——工程创建
- PhoneGap学习笔记(1)
- phonegap自定义插件 笔记
- phonegap学习1——phonegap说明和整体架构
- MAC下创建phonegap工程
- phonegap学习笔记(一)--HelloWorld,第一个工程
- 安装配置PhoneGap开发环境(二)——使用Cordova代替PhoneGap创建项目
- Phonegap使用device插件
- 空间滤波基础
- sudo
- 字符串的合并
- 11、接口——interface
- 【java】Volatile使用与理解
- phonegap学习笔记1——创建工程 使用插件
- ActionBar隐藏与出现
- linux下jrtplib库移植到android上
- 内核模块遍历进程和任务队列保存到proc文件中
- 12、static与final关键字详解
- 第二周课程管理实践总结
- 二叉查找树及平衡二叉查找树
- 快速排序
- MATLAB学习笔记(三)