简体   繁体   English

带有getpicture的Phonegap 3(apache cordova)错误(无法读取属性“ PictureSourceType”和DATA_URL

[英]Phonegap 3 (apache cordova) error with getpicture (Cannot read property 'PictureSourceType' and DATA_URL

I'm newbie in developing web applications with apache 3.3.0 cordova. 我是使用Apache 3.3.0 cordova开发Web应用程序的新手。 take days trying to start the camera and use the plugin filetransfer but always gives me the same error. 尝试启动相机并使用插件文件传输需要花几天时间,但始终会给我同样的错误。

if I use my application with phonegap 2.9 everything works perfectly, 如果我将我的应用程序与phonegap 2.9一起使用,则一切运行正常,

STEPS I followed to create my project with 3.3.0 cordova 我遵循的步骤使用3.3.0 cordova创建我的项目

I used command line to create a Hello app installing the necessary plugins such as the camera or filetransfer. 我使用命令行创建了一个Hello应用,该应用安装了必要的插件,例如相机或文件传输。

I added permissions in the manifest i plugins in config.xml. 我在config.xml的清单清单中添加了权限。

This can not be the problem. 这不是问题。 Would greatly appreciate help. 非常感谢您的帮助。 I'm working with Eclipse and developing on Android 4.4.2. 我正在使用Eclipse并在Android 4.4.2上进行开发。

Index.html Index.html

    <!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" src="js/index.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>

Manifest 表现

    <?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" android:windowSoftInputMode="adjustPan" package="com.example.hello" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="helloclimbing" android:theme="@android:style/Theme.Black.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.RECORD_VIDEO" />
        <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
</manifest>

Config.xml Config.xml

    <?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.hello" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>Hello Cordova</name>
    <preference name="loglevel" value="DEBUG" />
    <feature name="App">
        <param name="android-package" value="org.apache.cordova.App" />
    </feature>
    <name>helloclimbing</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <feature name="Device">
        <param name="android-package" value="org.apache.cordova.device.Device" />
    </feature>
    <feature name="NetworkStatus">
        <param name="android-package" value="org.apache.cordova.networkinformation.NetworkManager" />
    </feature>
    <feature name="Camera">
        <param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
    </feature>
    <feature name="File">
        <param name="android-package" value="org.apache.cordova.file.FileUtils" />
    </feature>
    <feature name="Capture">
        <param name="android-package" value="org.apache.cordova.mediacapture.Capture" />
    </feature>
    <feature name="FileTransfer">
        <param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
    </feature>
    <feature name="InAppBrowser">
        <param name="android-package" value="org.apache.cordova.inappbrowser.InAppBrowser" />
    </feature>
    <feature name="http://api.phonegap.com/1.0/device" />
<feature name="http://api.phonegap.com/1.0/camera"/>
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/media"/>
<feature name="http://api.phonegap.com/1.0/network"/>
</widget>

You don't have to manually edit AndroidManifest.xml or config.xml to install a plugin. 您无需手动编辑AndroidManifest.xml或config.xml即可安装插件。 See my answer at https://stackoverflow.com/a/20813323/529323 https://stackoverflow.com/a/20813323/529323上查看我的答案

I've tried your code and the "Get picture" function works. 我已经尝试过您的代码,并且“获取图片”功能有效。 Just install the plugins in the proper way. 只需以正确的方式安装插件即可。

Try to install all required phone gap plugins using command line 尝试使用命令行安装所有必需的电话间隙插件

cordova plugin add org.apache.cordova.network-information
cordova plugin add org.apache.cordova.media
cordova plugin add org.apache.cordova.camera

It worked with me! 它与我合作!

The Problem, from what I gather, is the CPU. 据我了解,问题出在CPU。 Any device running 4.4.2 with an ARM CPU wont run the app made with Cordova. 任何运行带有ARM CPU的4.4.2的设备都不会运行由Cordova开发的应用程序。 If it uses any other, it does. 如果使用其他任何方法,则使用。 That's why for some it works and for others it doesn't. 这就是为什么它对某些人有效,而对另一些人无效的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Phonegap Camera API-无法读取未定义的属性“ DATA_URL” - Phonegap Camera API - Cannot read property 'DATA_URL' of undefined cordova给出TypeError:无法读取undefined:68的属性&#39;DATA_URL&#39; - cordova giving TypeError: Cannot read property 'DATA_URL' of undefined:68 无法读取undefined - 离子相机的属性&#39;getPicture&#39; - Cannot read property 'getPicture' of undefined - ionic camera Phonegap 3.5.0 Cordova File API错误:无法读取未定义的属性“ dataDirectory” - Phonegap 3.5.0 Cordova File API Error: cannot read property 'dataDirectory' of undefined 使用camera.getPicture拍照后,Cordova / phonegap崩溃 - Cordova/phonegap crashes after taking a picture with camera.getPicture Phonegap错误 - “在Android上无法读取未定义的属性&#39;捕获&#39; - Phonegap Error - “Cannot read property 'capture' of undefined” on Android 开始使用PhoneGap时遇到麻烦:Apache Cordova错误 - Trouble with getting started on PhoneGap: Apache Cordova error cordova成功错误TypeError:无法读取null的属性&#39;filesystemName&#39; - cordova Error in Success TypeError: Cannot read property 'filesystemName' of null 无法在Cordova网络插件中读取未定义错误的属性“类型” - Cannot read the property 'type' of undefined error in cordova network plugin Cordova Android构建错误“无法读取未定义的属性&#39;长度&#39; - Cordova Android build error “Cannot read property 'length' of undefined”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM