SDL2 Android Asset Path - java

I need to grab the path to the android assets folder for my SDL2 app. I keep getting file not found when I attempt to get the file directly with something simple like:
TTF_OpenFont("font.ttf", 24 );
What I assume is that I'm looking in the wrong folder (whatever the current working directory is), and that I need to prepend the assets folder path.
Using SDLActivity.getContext().getAssets().list(""); shows the file i want to load.
Ironically, loading "font.ttf.png" does not result in a FileNotFoundException (I randomly added .png as a sanity check... I'm not sure I'm sane anymore).
I have been loading them fine on other platforms (win, linux, osx).

Related

What is the right way (resp. folder) to save files under Android 11 (API30)?

My Android-APP creates text files that have to be read by other apps.
I originally chose the following directory, which no longer works:
Environment.getExternalStoragePublicDirectory((Environment.DIRECTORY_DOCUMENTS))
Right now I'm trying the directory:
getFilesDir()
The problem here is that no other app can access this folder.
I'm puzzled as I simply don't know which directory I can use for an exchange between apps.

Extraction APK : what are .png# files?

I would like to extract the images from an android game.
Firstly, I took the APK on my windows 10 laptop then I extracted the files (rename files.apk to files.apk.zip and extracted it with 7zip).
Inside my folders I got many .png files but I get an error when I try to open one. Each .png file has another file with the same name but with .png#. Some even have 2 otherfiles with them : one with .skel (can't open this one too) and .atlas (I can open it with notepad):
Did I make mistakes? What can I do to "repair" all these png files?
Thank you for you help!
If you are authorised to do so then you can apktool.
Its easy to use and may that #png files will be converted to some meaningful resource.
Installation for Apktool
Windows:
Download Windows wrapper script (Right click, Save Link As apktool.bat)
Download apktool-2 (find newest here)
Rename downloaded jar to apktool.jar
Move both files (apktool.jar & apktool.bat) to your Windows directory (Usually C://Windows)
If you do not have access to C://Windows, you may place the two files anywhere then add that directory to your Environment Variables System PATH variable.
Try running apktool via command prompt
Link

How can I create a flexible medium for accessing png/bmp files with code so my code will run in Eclipse, as well as after it is exported?

I am making an application that searches the screen for a specific image. I read the picture (file) I am scanning for and convert it to a buffered image, then to an int[] so I can process it faster. I also use the robot class to take a screenshot and convert to an int[].
While running code in Eclipse and having the files in the source folder, I don't have any problems. But after exporting my code to a runnable jar file, my scanning methods no longer work. I think it might have something to do with compression because my pictures need to be exactly how they were taken.
The only success I have had with a "finished format" is by exporting the jar normally, and using a folder in the same directory called images to hold the files. Using this code:
File img = new File(System.getProperty("user.dir") + File.separator + "images" + File.separator + "Close.bmp");
When running directly from eclipse I can simply do this:
File img = new File(src/Close.bmp);
Any suggestions? Maybe some tips/settings on exporting jars?
You have various options:
probably the easiest is to put the image in the classpath, i.e. deploy it with your class files, probably within a jar file. The drawback is that you can't replace the image (as long as you don't want your user to fiddle with the classpath)
place it relative to the user.dir as you have done, in this case you need to understand what the user.dir actually is: The working directory from which your application got started. It will differ depending on how you start it.
another option is to use a path relative to user.home which is your home directory.

Start my application from my home folder (relative path)

This is a 100% win console application.
So here's the problem.
I want to load the file music.xm that I want to place inside the jar.
The problem come up when I try to call the file through a relative path. The start directory it's not the Java project one, but my Windows User Folder.
If I call
File music = new File("\\music.xm");
javax.sound.sampled.UnsupportedAudioFileException: /C:/Users/XXXX/Desktop/./music/music.xm
If I call
File music = new File(".\\music.xm");
I get
javax.sound.sampled.UnsupportedAudioFileException: /C:/music.xm
If its in your jar, you can use
getclassLoader().getResourceAsStream("music.xm")
You can use this inputStream however you like. But remember, the path should be relative to classpath root of the classloader.
In addition, if you are sure "music.xm" exists as an independent file on filesystem in a fixed relative location to your .class files you can also use :
getclassLoader().getResource("music.xm")
You can look on SO and here for documentation.

Find a resource both in .jar and eclipse with the same String computation

I want to get the path to a resource for ImageIO to read out a BufferedImage from some .png s.
While developing the project I use a relative path to "/bin/stuff/icons/image.png" , but this will definetly not work when I put everything together into a .jar file, so I need a way to get the path to these resources both while testing in eclipse and when later running it within a .jar .
After a lot of trying out both finding the file and getting the input stream to the file I came to the conclusion that this approach works every time:
InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream(path)
BufferedImage image = ImageIO.read(in)
Where path is
"projectName/resourceFolder/" + nameOfResource.stuff
as found in the src directory of the eclipse project.
E.g.
"myProject/images/icon.png"
When getting only the resource and then getting the path of the resource to link to a file, you will get FileNotFoundExceptions when using a .jar (but not while testing with eclipse, so one should be warned to think that his code works).
And - no - I don't save images in the bin/ - but they are copied to this directory and thus I find them there while testing. Now everything seems to be working.
Don't put anything under the bin directory in Eclipse: if you run a clean on the project it will be erased.
What you can do is to define a new source folder like resources, and put the image there. This way it will be automatically copied to the bin folder.
If you include the resources folder into the Jar, it will be available in both environments by using something like:
ImageIO.read( getClass().getResource("/image.png") )
PS: You can evade using a different resources folder but mixing the sources and images will quickly pollute your source folder.

Categories