小编Gab*_*ira的帖子

当我尝试在 Android 11 中读取文件时出现电容文件系统错误

readFile我尝试使用电容器文件系统的功能读取模拟器中的文件。我尝试操作它的文件位于模拟器的下载文件夹中,并且该函数返回以下错误:

\n
\n

错误:文件不存在

\n
\n

我还尝试使用复制功能,将此文件复制到可以操作它的目录,但此函数返回此错误:

\n
\n

错误:源对象不存在

\n
\n

我还在应用程序中进行了权限测试,我得到了granted.

\n

我在网上搜索了这个错误,但没有成功。Directory我还使用了文件系统服务功能上的所有参数,但所有选项都返回相同的错误。使用相同的参数,可以访问 Android 10 中的文件系统。

\n

所有测试均在运行 Android 11 (API30) 的 Pixel 4 模拟器中进行。

\n

在 android.xml 的标签内application,我添加了android:requestLegacyExternalStorage="true", 和user-permissions

\n
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />\n<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />\n<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />\n
Run Code Online (Sandbox Code Playgroud)\n

主页.ts

\n

带副本

\n
// file_dir_path = file:///storage/emulated/0/Download/\n// file_name = file.kml\n// path = \'MyApp/project\' + this.projectId + \'/temp\'\nreturn this.filesystem.copyFileToManegeDirectory(file_dir_path + file_name, path + \'/teste\').then(fileAs64 => …
Run Code Online (Sandbox Code Playgroud)

android typescript ionic-framework capacitor

7
推荐指数
1
解决办法
5505
查看次数

尝试使用离子/电容器访问物理设备中的文档文件夹时无法解析文件系统路径

我正在开发一个函数来捕获和读取 KML 文件,以及另一个函数来解压缩并保存 KMZ 文件(基本上是 zip)内的这些文件。

在第一次尝试中,我无法访问它,因为错误告诉我我没有正确的权限,但根据电容器文档和添加后android:requestLegacyExternalStorage="true"AndroidManifest.xml我可以获得访问设备文件的正确权限。之后,我必须使用FilePathFilePath.resolveNativePath(path);中的函数来过滤 URI 。原始路径由 生成,URI 是文件的根路径。fileChooser.open().then(uri=>{})

在使用 API 29/v10 和 API 30/v11 的 Android 模拟器以及使用 API 29/v10 的物理 Android 设备进行一些测试后,我能够使这些功能正常工作,但在物理设备中有一个特定的文件夹 Documents,无法访问并生成错误:

“错误错误:未捕获(承诺):对象:{“code”:0,“message”:“无法解析文件系统路径。”}”。

页面.ts:

selectFile(): Promise<void>{
    if (this.platform.is('cordova')) {
        return this.fileChooser.open().then(uri => {
            return this.filePath.resolveNativePath(uri).then(uri => {
                let filename = uri.split('/').pop();
                this.layerName = filename;
                this.fileURI = uri;
            });
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑

版本前的 URI:content://com.android.externalstorage.documents/document/home%3Apoligono.kml.

版本后的 URI:运行函数 FilePath.resolveNativePath(uri); 后发生错误。这种情况仅发生在物理设备中的这个特定文件夹中。

文件夹文档:

文件夹文档

android typescript ionic-framework angular capacitor

5
推荐指数
0
解决办法
1745
查看次数