我尝试使用相机拍照并将图像的路径存储在数据库中。我已经编写了使用相机拍照的代码。相机打开,然后在相机取消时显示错误信息。 这是我的js代码:
.controller('cameractrl', function($scope, Myfactory,$window,$cordovaSQLite)
{
alert("cameractrl");
$scope.capturePhoto=function()
{
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
sourceType :Camera.PictureSourceType.CAMERA,
destinationType: Camera.DestinationType.FILE_URI, });
}
function onPhotoDataSuccess(imageURI) {
alert("got image file entry: " + fileEntry.fullPath);
}
我在AndroidManifest中添加了以下权限:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
在config.xml中我添加了这个:
<plugin name="Camera" value="org.apache.cordova.CameraLauncher" />
但是相机还在打开吗?然后关闭警报摄像头已取消。 任何解决方案???
这是我的config.xml
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.ionicframework.starter" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<preference name="loglevel" value="DEBUG" />
<feature name="Keyboard">
<param name="android-package" value="com.ionic.keyboard.IonicKeyboard" />
<param name="onload" value="true" />
</feature>
<feature name="AdMob">
<param name="android-package" value="com.rjfun.cordova.plugin.AdMob" />
</feature>
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<feature name="Camera">
<param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
</feature>
<feature name="SQLitePlugin">
<param name="android-package" value="org.pgsqlite.SQLitePlugin" />
</feature>
<feature name="File">
<param name="android-package" value="org.apache.cordova.file.FileUtils" />
<param name="onload" value="true" />
</feature>
<feature name="FileTransfer">
<param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
</feature>
<feature name="Media">
<param name="android-package" value="org.apache.cordova.media.AudioHandler" />
</feature>
<name>HelloCordova</name>
<description>
An Ionic Framework and Cordova project.
</description>
<author email="hi@ionicframework" href="http://ionicframework.com/">
Ionic Framework Team
</author>
<content src="index.html" />
<access origin="*" />
<preference name="webviewbounce" value="false" />
<preference name="UIWebViewBounce" value="false" />
<preference name="DisallowOverscroll" value="true" />
<preference name="BackupWebStorage" value="none" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<preference name="AndroidExtraFilesystems" value="files,files-external,documents,sdcard,cache,cache-external" />
<plugin name="Camera" value="org.apache.cordova.CameraLauncher" />
答案 0 :(得分:3)
这个问题已经很老了,但今天我来这里搜索这个问题。对于具有相同问题的其他用户,请添加config.xml:
<preference name="AndroidLaunchMode" value="standard"/>
答案 1 :(得分:0)
Buddy,你缺少设置:encodingType和mediaType。
检查我的例子:
var cameraOptions = {
quality : quality,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
encodingType: Camera.EncodingType.JPEG,
mediaType: Camera.MediaType.PICTURE,
targetWidth: targetWidth,
targetHeight: targetHeight,
saveToPhotoAlbum: saveToPhotoAlbum
};
我建议您使用JPEG而不是PNG。