在 android 上添加要在 javafxports 中读取和写入的文件
adding file to be read and write in javafxports on android
我想在我的 JavaFXPorts Android 和 iOS 上有一些配置文件。
不过好像没想象中那么简单
有人知道解决方案吗?
我已经试过了。在我的概念证明中,我有 XML 文件,它可以读写。当我将它部署到 java jar 时,它工作得很好。但是在 android 上似乎找不到 xml 文件。
这里是这些概念证明的回购协议。
https://bitbucket.org/bluetonic/xmlreadwritefx
请随时检查:)
此致,
伊万
对于Android,你的apk安装在某个路径下,你可以通过Context.getFilesDir()
(link)检索你的文件可以存储的本地路径:
Returns the absolute path to the directory on the filesystem where files created with openFileOutput(String, int) are stored.
为了从您的 JavaFX 线程访问上下文,您需要使用:
Context context = FXActivity.getInstance();
现在您可以使用上述方法检索文件了。
例如,您可以在 Android/Java 包上创建此助手 class:
import javafxports.android.FXActivity;
import android.content.Context;
import java.io.File;
public class FileManager {
private final Context context;
public FileManager(){
context = FXActivity.getInstance();
}
public File getFile(String fileName){
return new File(context.getFilesDir(), fileName);
}
}
现在,如果您在 Android 上 运行,则可以调用此 class 的实例,而如果您是 运行,则仍然可以使用标准方法在桌面上。
查看此博客 post 以了解如何使用 PlatformProvider
。我用它来读写 属性 个文件,但我看不出 XML 个文件有什么区别。
我想在我的 JavaFXPorts Android 和 iOS 上有一些配置文件。 不过好像没想象中那么简单
有人知道解决方案吗?
我已经试过了。在我的概念证明中,我有 XML 文件,它可以读写。当我将它部署到 java jar 时,它工作得很好。但是在 android 上似乎找不到 xml 文件。
这里是这些概念证明的回购协议。 https://bitbucket.org/bluetonic/xmlreadwritefx 请随时检查:)
此致,
伊万
对于Android,你的apk安装在某个路径下,你可以通过Context.getFilesDir()
(link)检索你的文件可以存储的本地路径:
Returns the absolute path to the directory on the filesystem where files created with openFileOutput(String, int) are stored.
为了从您的 JavaFX 线程访问上下文,您需要使用:
Context context = FXActivity.getInstance();
现在您可以使用上述方法检索文件了。
例如,您可以在 Android/Java 包上创建此助手 class:
import javafxports.android.FXActivity;
import android.content.Context;
import java.io.File;
public class FileManager {
private final Context context;
public FileManager(){
context = FXActivity.getInstance();
}
public File getFile(String fileName){
return new File(context.getFilesDir(), fileName);
}
}
现在,如果您在 Android 上 运行,则可以调用此 class 的实例,而如果您是 运行,则仍然可以使用标准方法在桌面上。
查看此博客 post 以了解如何使用 PlatformProvider
。我用它来读写 属性 个文件,但我看不出 XML 个文件有什么区别。