You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.
Hello, I'm a user of the LibGDX framework which abstracts native Android code (for the most part), so I have limited experience with native Android programming. File access used to work great until the introduction of scoped storage and I'm hoping ModernStorage will make file access a lot simpler because I got a migraine trying to look into the Storage Access Framework. lol
For testing, I created a new Android project in Android Studio (bypassing LibGDX entirely for right now) and I have ModernStorage setup in a blank test project. I have a directory on the main storage of my phone called 'ztest' with one file in it and I would like to list this directory.
I am using Java and here is my code:
// LIST DIRECTORY
FileSystem fileSystem = new AndroidFileSystem(this);
String pathString = "ztest";
ByteString byteString = new ByteString(pathString.getBytes());
Path path = new Path(byteString);
List<Path> list = null;
try {
list = fileSystem.list(path);
} catch (IOException e) {
e.printStackTrace();
}
But I'm already stuck on a couple issues:
How to get a file path that I can use with ModernStorage. In LibGDX before Scoped Storage, I used one of the LibGDX methods to get a FileHandle for a directory or folder by using a String for it's path. I'm not sure how to accomplish this for use with ModernStorage. I do not think the pathString or byteString is correct, but I'm not sure what to do there.
Since I'm using Java instead of Kotlin, it appears that ModernStorage returns a Kotlin List when calling fileSystem.list(path). This seems to be incompatible using Java.
To address issue 2, I tried adding Kotlin to my project and added a Kotlin file to work with ModernStorage.
Here is my Kotlin code:
// LIST DIRECTORY
var fileSystem: FileSystem = AndroidFileSystem(context)
var pathString: String = "ztest"
var byteString: ByteString = pathString.getBytes()
var path: Path = Path(byteString)
var list: List<Path>? = null
try {
list = fileSystem.list(path);
}catch ( e:java.io.IOException) {
e.printStackTrace()
}
Now I am getting an error on pathString.getBytes(), but I'm pretty sure this whole thing is wrong anyways. This is my first time trying to use Kotlin, so I know some of the syntax is wrong (getting errors). If it's not possible to use ModernStorage with Java, then I'll look into Kotlin more.
I feel like once I can get a file or directory working with the FileSystem, then all the other methods are pretty straight forward. I realize ModernStorage is still in alpha and not all the functionality is completed yet, but once I know I can get it working and implemented with LibGDX then I'll wait for it to be completed. Thank you.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello, I'm a user of the LibGDX framework which abstracts native Android code (for the most part), so I have limited experience with native Android programming. File access used to work great until the introduction of scoped storage and I'm hoping ModernStorage will make file access a lot simpler because I got a migraine trying to look into the Storage Access Framework. lol
For testing, I created a new Android project in Android Studio (bypassing LibGDX entirely for right now) and I have ModernStorage setup in a blank test project. I have a directory on the main storage of my phone called 'ztest' with one file in it and I would like to list this directory.
I am using Java and here is my code:
But I'm already stuck on a couple issues:
How to get a file path that I can use with ModernStorage. In LibGDX before Scoped Storage, I used one of the LibGDX methods to get a FileHandle for a directory or folder by using a String for it's path. I'm not sure how to accomplish this for use with ModernStorage. I do not think the pathString or byteString is correct, but I'm not sure what to do there.
Since I'm using Java instead of Kotlin, it appears that ModernStorage returns a Kotlin List when calling fileSystem.list(path). This seems to be incompatible using Java.
To address issue 2, I tried adding Kotlin to my project and added a Kotlin file to work with ModernStorage.
Here is my Kotlin code:
Now I am getting an error on pathString.getBytes(), but I'm pretty sure this whole thing is wrong anyways. This is my first time trying to use Kotlin, so I know some of the syntax is wrong (getting errors). If it's not possible to use ModernStorage with Java, then I'll look into Kotlin more.
I feel like once I can get a file or directory working with the FileSystem, then all the other methods are pretty straight forward. I realize ModernStorage is still in alpha and not all the functionality is completed yet, but once I know I can get it working and implemented with LibGDX then I'll wait for it to be completed. Thank you.
Beta Was this translation helpful? Give feedback.
All reactions