简体   繁体   English

Cordova android输入文件:无法访问设备上的某些目录

[英]Cordova android input file: cannot access some directories on device

My app, based on Cordova, allows users to upload images and PDF files to server. 我的应用程序基于Cordova,允许用户将图像和PDF文件上传到服务器。 I'm using a simple <input type="file"> with the Dropzone.js plugin for layout and transport. 我正在使用一个简单的<input type="file">和Dropzone.js插件进行布局和传输。 It works fine for both iOS and Android. 它适用于iOS和Android。 After clicking a button the file manager starts, you can choose file and it gets uploaded. 单击文件管理器启动的按钮后,您可以选择文件并上传。

The problem is, on Android the user cannot choose files from directories in the upper part of the file selector. 问题是,在Android上,用户无法从文件选择器上部的目录中选择文件。 I have an LG G4, so I cannot choose from Last files, Google Drive, Images, Downloaded, Internal memory. 我有一个LG G4,所以我不能选择上一个文件,谷歌硬盘,图像,下载,内存。 I can choose from Gallery, Photos and File manager without any problem, but not any directory above the line. 我可以选择图库,照片和文件管理器没有任何问题,但不能在线上方的任何目录。

I have permissions to read external storage. 我有权读取外部存储空间。 What am I missing here? 我在这里错过了什么?

Here's screen from the tester: 这是测试人员的屏幕: 屏幕形成测试仪

Dropzone html, its as basic as it gets. Dropzone html,它的基本功能。 Dropzone does not add here input type=file, but, much like jQuery, does it on the fly when file is selected. Dropzone不会在这里添加输入类型=文件,但是,就像jQuery一样,它会在选择文件时动态执行。

<form action="file-upload" class="dropzone dropzone-form dz-clickable" rem="dropform" id="dropzone-form">
            <input type="hidden" name="userId" value.bind="user_id" class="au-target" au-target-id="164">
            <div class="text-center add_btn_wrapper">
                <a class="btn btn-default btn-md dz-clickable" rem="dropbutton">Select file</a>
            </div>
            <div class="dz-default dz-message">
                <span>Upload your scans</span>
            </div>
    </form>

Dropzone js declaration (I'm using Aurelia.js (es5/6) as frontend framework): Dropzone js声明(我使用Aurelia.js(es5 / 6)作为前端框架):

this.zone = new Dropzone(
    _this.element.querySelector("[rem='dropform']"), { 
        url: this.auth.config.baseUrl + "../_uploader/file/upload",
        maxFiles: this.max_files,
        acceptedFiles: this.accepted_files,
        clickable: [_this.element.querySelector("[rem='dropbutton']"), _this.element.querySelector("[rem='dropform']")],
        dictDefaultMessage: this.label,
        addRemoveLinks: this.allow_remove,
        removedfile: (file) => { .... },
        init: function() {
            this.on("addedfile", (fx) => { .... });
            this.on("complete", (fx) => { .... });
        }
    });

And in AndroidManifest.xml: 在AndroidManifest.xml中:

<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"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>

Ok, the problem was caused by acceptedFiles parameter. 好的,问题是由acceptedFiles参数引起的。 For desktop I had there "image/*,.pdf" and it worked, but cordova with this value got confused and limited my access. 对于桌面我有"image/*,.pdf"并且它有效,但具有此值的cordova感到困惑并限制了我的访问权限。 For mobile I'm using now just "image/*" , and it works as it should. 对于移动设备我现在只使用"image/*" ,它可以正常工作。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM