3

I have a problem to save Files on Android with JavaFxPorts.

I've found that link here, but it doesn't work for me.

Error

It doesn't found the Interface, and I can't use it.

My goal is to save a file on Android with JavaFxports.

Thanks

Community
  • 1
  • 1
Aaron Stein
  • 526
  • 7
  • 18

1 Answers1

4

If you are trying to add some code in the Android folder, make sure you add correctly the GluonPlatform class in the main project. You can have a look at the GoNative sample in Gluon's sample repository, for finding out how to do it.

But to save a file in the app's local folder on your mobile device, you can use Gluon's Charm-Down open source library.

It contains common API for several platform specific services.

You just need to add it to your dependencies on the build.gradle script:

ext.CHARM_DOWN_VERSION = “1.0.0”

dependencies {
    compile "com.gluonhq:charm-down-common:$CHARM_DOWN_VERSION"
    desktopRuntime "com.gluonhq:charm-down-desktop:$CHARM_DOWN_VERSION"
    androidRuntime "com.gluonhq:charm-down-android:$CHARM_DOWN_VERSION"
    iosRuntime "com.gluonhq:charm-down-ios:$CHARM_DOWN_VERSION"
}

Save, and rebuild your project (so those dependencies are included), and now on your main project you can ask for the local path on your device, and access to the file:

public File getFile() {
    File path = PlatformFactory.getPlatform().getPrivateStorage();
    return new File(path, "config.xml");
}
José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • Thanks for your fast answer. The file creates succesfully but there is a problem: I can't read/write the file do you got a solution for that? – Aaron Stein Dec 19 '15 at 18:30
  • Once you have the File, you may need a FileWriter and FileReader. Check this [link](https://github.com/jperedadnr/Game2048FX/blob/master/src/main/java/org/jpereda/game2048/SessionManager.java) for a sample of file storage – José Pereda Dec 19 '15 at 19:22
  • Thanks for this answer later i'll try it with this. I used xml before and maybe try now Proberties. Thanks for the fast answer. – Aaron Stein Dec 20 '15 at 10:50
  • can you take a look to that : http://stackoverflow.com/questions/34382211/javafx-gluon-save-xml-file – Aaron Stein Dec 20 '15 at 14:50
  • @JoséPereda Hi! I cannot find the Charm Down examples in the URL link. – euraad Aug 08 '19 at 22:09
  • @JoséPereda Is Charm Down included in Gluon by default? – euraad Aug 08 '19 at 22:13
  • @Heretic This answer is way too old anyway. Check an updated version of Go Native here: https://github.com/gluonhq/gluon-samples/tree/master/go-native. And the rest of the Gluon Mobile samples https://github.com/gluonhq/gluon-samples/ that make use of `StorageService`, so you don't have to implement it yourself. – José Pereda Aug 08 '19 at 22:14
  • @Heretic Charm Down is OSS and it is dual licensed. You can use it without Gluon Mobile, but it is GPL. If you have a Gluon Mobile commercial license, you can use Charm Down. See https://gluonhq.com/products/mobile/attach/ (Attach is the new name). – José Pereda Aug 08 '19 at 22:17
  • @JoséPereda I don't know what Charm Down is. Tried to search for it on google, but didn't give me a clear answer. Ok! I can probably use StorageService for mobile version! I don't have a license, but I think my company will buy one soon. By the way, can I get a free license from Gluon if I have a opensource project on GitHub? It's going to be a deep learing project with many hours working on it. – euraad Aug 08 '19 at 22:25
  • @Heretic I've posted the link to Attach (Charm Down), so you can find more about it there. There are free licenses for OSS projects: https://gluonhq.com/programs/free-gluon-licenses/ – José Pereda Aug 08 '19 at 22:27