Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/456.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Kitkat操作系统上的cordova摄像头插件问题_Javascript_Java_Android_Cordova - Fatal编程技术网

Javascript Kitkat操作系统上的cordova摄像头插件问题

Javascript Kitkat操作系统上的cordova摄像头插件问题,javascript,java,android,cordova,Javascript,Java,Android,Cordova,我正在使用cordova camera插件拍照,然后将其上传到服务器。我一直在手机中使用棒棒糖操作系统,它在手机中运行得很好。但是,当我在朋友的手机上测试该应用程序时,该应用程序在Kitkat操作系统上运行,会抛出一条错误消息。下面给出了该应用程序的屏幕截图 <?xml version='1.0' encoding='utf-8'?> <manifest android:hardwareAccelerated="true" android:versionCode="1" and

我正在使用cordova camera插件拍照,然后将其上传到服务器。我一直在手机中使用棒棒糖操作系统,它在手机中运行得很好。但是,当我在朋友的手机上测试该应用程序时,该应用程序在Kitkat操作系统上运行,会抛出一条错误消息。下面给出了该应用程序的屏幕截图

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" 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" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
</manifest>
给定图像的文件URI类似于 'file:///storage/emulated/0/Android/data/com.app.name/cache/filename.jpg’。下面给出了我的JavaScript代码

 //function that gets called when clicking capture photo button
                function capturePhoto() {
                navigator.camera.getPicture(onCapturePhoto, onFail, {
                quality: 50,
                destinationType: Camera.DestinationType.FILE_URI
                });



 function onCapturePhoto(fileURI) {

                var win = function (r) {
                clearCache();
                retries = 0;
                BootstrapDialog.alert('Done uploading image!');
                var img = JSON.parse(r.response);
                $("#clientid_issue_id").val(img.id.$id);
                construct_img_thumbnail_view(img);
                $("#go_to_issue_report_btn").prop('disabled', false);
                }

                var fail = function (error) {
                if (retries == 0) {
                retries++
                setTimeout(function () {
                onCapturePhoto(fileURI)
                }, 5000)
                } else {
                retries = 0;
                clearCache();
                BootstrapDialog.alert('Ups. Something wrong happens!' + JSON.stringify(error));
                $("#go_to_issue_report_btn").prop('disabled', false);
                }
                }

                var options = new FileUploadOptions();
                options.fileKey = "file";
                options.fileName = fileURI.substr(fileURI.lastIndexOf('/') + 1);
                options.mimeType = "image/jpeg";
                var params = new Object();
                params.client_device_id = device.uuid;
                params.client_issue_id = $("#clientid_issue_id").val();
                if (params.client_issue_id.trim() === "")
                {
                params.client_issue_id = 0;
                }
                options.params = params; // if we need to send parameters to the server request
                var ft = new FileTransfer();
                $("#go_to_issue_report_btn").prop('disabled', true);
                ft.upload(fileURI, encodeURI(SERVER_PATH + "/services/uploadimage"), win, fail, options);
                }
我使用的cordova版本是5.1.1。下面给出了AndroidManifest.xml文件

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" 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" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="22" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
</manifest>
这是我的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">
    <preference name="loglevel" value="DEBUG" />
    <allow-intent href="market:*" />
    <name>HelloWorld</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="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <feature name="Whitelist">
        <param name="android-package" value="org.apache.cordova.whitelist.WhitelistPlugin" />
        <param name="onload" value="true" />
    </feature>
    <feature name="Camera">
        <param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
    </feature>
    <feature name="Device">
        <param name="android-package" value="org.apache.cordova.device.Device" />
    </feature>
    <preference name="AndroidPersistentFileLocation" value="Internal" />
    <preference name="AndroidPersistentFileLocation" value="Compatibility" />
    <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>
</widget>

如果有人能告诉我解决方案,那将非常有帮助。

事实上,我发现了这个问题。服务器路径变量的值是从存储在设备上的外部文本文件read.txt中读取的。因此,在我的朋友手机中,read.txt是用一个名为金山办公软件的应用程序编辑的。给出的路径是正确的服务器路径,并保存了该路径。该应用程序启动后可以很好地读取文件中的值。但是在拍照和上传的代码部分,我使用了类似“ft.uploadfileURI,encodeURISERVER_path+/services/uploadimage,win,fail,选项;'。我使用AlertEncodeURI服务器\ u PATH+/services/uploadimage检查服务器路径是否正确。令人惊讶的是,发出警报的值不是实际的服务器地址。因此,我将read.txt文件从手机发送到friends mobile并再次测试应用程序。现在,即使我使用encodeURI,我也会得到正确的服务器地址。希望这可能有用对于其他可能遇到类似情况的人来说。

似乎您的服务器正在阻止您的应用程序request@lifeisfoo同样的应用程序在我的手机上运行很好,它运行在棒棒糖上,图像上传到服务器上,所以我认为这可能不是服务器的问题。屏幕截图来自在Kitkat操作系统上运行的手机。你调试过这个应用程序吗服务器上的请求?你能分享管理上传的php服务器端代码吗?请使用我提供给你的所有信息回答你自己并接受答案,这样其他人就可以解决类似的问题。如果我的建议/意见对你有用,请投票表决。