android - 使APP android读取文件的内容 - IONIC
问题描述
我的问题是,如果可以从一个.properties
或.txt
文件中获取一个变量。我需要它来保存endPoint
服务器 IP 地址。这样,每次更改IP地址时,您只需更改文件上的IP,而不是再次编译代码并构建apk,然后在设备上重新安装。欢迎任何提示。
更新
我一直在尝试使用这个插件:File,但没有成功。我想使用readAsText(path,file)
,但我得到的只是未定义
import { File } from '@ionic-native/file/ngx';
constructor(
....
private file : File,
....
) { }
async test(){
this.promise = this.file.readAsText('file:///data/','ipAddress.txt');
await this.promise.then(value => {
console.log(value)
}).catch(error=> console.log("nao existe"))
}
我收到以下错误:
ERROR Error: Uncaught (in promise): FileError: {"code":1,"message":"NOT_FOUND_ERR"}
更新 问题已解决。我试图访问内部存储,而文档在外部存储上。确保您使用 URI,android 上的路径与计算机不同。您需要 URI。
file:///storage/emulated/0/Android/data/
当设备准备就绪时,我立即调用了该方法app.component.ts
ngOnInit() {
.....
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.api.getURL();
.....
});
}
希望我能帮助下一个解决我遇到的同样问题。
解决方案
推荐阅读
- python - Run Jupyter lab container on given virtualenv
- c++ - problem compiling with different gcc versions
- c - How can I compare user input to string stored into file?
- javascript - 如何每 10 秒在数组中显示一个随机字符串
- django - 如何在多对多关系中访问另一个字段?
- python - 有没有更好的方法来检查按顺序更改的值?
- ruby-on-rails - 如何让我的 Rails 应用程序可以被搜索引擎发现
- microsoft-graph-api - 如何向刚刚创建的计划者任务发送评论。对话线程对他们来说是空的
- flutter - 显示包的所有图标
- sql - 如何在 Access VBA 中运行双循环