gpt4 book ai didi

android - ionic - 读取 android Assets 文件

转载 作者:行者123 更新时间:2023-11-30 05:11:14 25 4
gpt4 key购买 nike

我正在尝试读取 android assets 子文件夹中的文件,我曾尝试使用 file.checkDir 和 file.checkFile 但似乎没有任何效果。这是一些 checkDir 代码:

  this.file.checkDir(
this.file.dataDirectory, 'file:///android_asset/xl72.png').then(
_ => alert('Directory exists')
).catch(err => alert('Directory doesn\'t exist'));

检查文件代码:

this.file.checkFile(this.file.dataDirectory, 'xl72.png').then(
(files) => {
alert('files found ' + files)
}
).catch (
(err) => {
alert(JSON.stringify(err))
}
);

有人知道怎么做吗?谢谢。

最佳答案

我还想从 assets 文件夹中打开文件,问题是很难找到它的路径。有了这个 fragment ,我发现它很容易:

    this.file.listDir(this.file.applicationDirectory, '')
.then( value => {
console.log(value);
});

结果:

[{"isFile":true,"isDirectory":false,"name":"chrome_100_percent.pak","fullPath":"/chrome_100_percent.pak","filesystem":"<FileSystem: assets>","nativeURL":"file:///android_asset/chrome_100_percent.pak"},{"isFile":false,"isDirectory":true,"name":"fallback-locales","fullPath":"/fallback-locales/","filesystem":"<FileSystem: assets>","nativeURL":"file:///android_asset/fallback-locales/"},{"isFile":true,"isDirectory":false,"name":"icudtl.dat","fullPath":"/icudtl.dat","filesystem":"<FileSystem: assets>","nativeURL":"file:///android_asset/icudtl.dat"},{"isFile":false,"isDirectory":true,"name":"images","fullPath":"/images/","filesystem":"<FileSystem: assets>","nativeURL":"file:///android_asset/images/"},{"isFile":true,"isDirectory":false,"name":"natives_blob.bin","fullPath":"/natives_blob.bin","filesystem":"<FileSystem: assets>","nativeURL":"file:///android_asset/natives_blob.bin"},{"isFile":true,"isDirectory":false,"name":"resources.pak","fullPath":"/resources.pak","filesystem":"<FileSystem: assets>","nativeURL":"file:///android_asset/resources.pak"},{"isFile":true,"isDirectory":false,"name":"snapshot_blob_32.bin","fullPath":"/snapshot_blob_32.bin","filesystem":"<FileSystem: assets>","nativeURL":"file:///android_asset/snapshot_blob_32.bin"},{"isFile":true,"isDirectory":false,"name":"snapshot_blob_64.bin","fullPath":"/snapshot_blob_64.bin","filesystem":"<FileSystem: assets>","nativeURL":"file:///android_asset/snapshot_blob_64.bin"},{"isFile":false,"isDirectory":true,"name":"stored-locales","fullPath":"/stored-locales/","filesystem":"<FileSystem: assets>","nativeURL":"file:///android_asset/stored-locales/"},{"isFile":true,"isDirectory":false,"name":"webapk6.dex","fullPath":"/webapk6.dex","filesystem":"<FileSystem: assets>","nativeURL":"file:///android_asset/webapk6.dex"},{"isFile":true,"isDirectory":false,"name":"webapk_dex_version.txt","fullPath":"/webapk_dex_version.txt","filesystem":"<FileSystem: assets>","nativeURL":"file:///android_asset/webapk_dex_version.txt"},{"isFile":false,"isDirectory":true,"name":"webkit","fullPath":"/webkit/","filesystem":"<FileSystem: assets>","nativeURL":"file:///android_asset/webkit/"},{"isFile":false,"isDirectory":true,"name":"www","fullPath":"/www/","filesystem":"<FileSystem: assets>","nativeURL":"file:///android_asset/www/"}]

深入挖掘后的最终结果是:

fullPath: "/www/assets/blink.bin"

最终结论。所有放在 project folder/www/assets 中的文件都可以通过以下路径访问:this.file.listDir(this.file.applicationDirectory, 'www/assets')

编辑即使我知道完整路径我也无法使用 file opener2 打开文件,然后我决定使用这个插件来查找和打开文件并且它工作得很好 https://ionicframework.com/docs/native/file

关于android - ionic - 读取 android Assets 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53716392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com