Reading txt, mp3 and other files from Android Studio - android

Recently I installed Android Studio, before I used Eclipse. While using Eclipse I could put all the files in Assets directory and access it using getassets method. For example:
InputStream ims = getAssets().open("textnew.txt");
Can you please advise:
Where to store files in Android Studio? Should I create folders in /res directory myself and put files there. For example: res/raw/textnew.txt
How to access those files? For example I need to open txt file in order to place its content to TextView. How to do it?
Thanks!

You can still use an asset folder in Android Studio.
Create manually a folder asset in your app directory.
Using the menus : File / New / Folder / Assets Folder
I think that the only difference with Eclispe is that in Android Studio the folder is not created by default.

Android Studio has a nice assistant to create an asset-folder. This way it will be created in the correct location.
Right Click on your project
Click "New" -> "Folder" -> "Assets-Folder"
Follow the assistant
Your folder should be created and will be added to your main-sourceset.

Related

Can't import assets from adobe XD into android studio

I made a UI layout using adobe XD and wanted to export it to use in android studio.
I achieved this by using the Export-kit plugin, which conveniently exported all my required assets for one page into a folder.
Exported assets folder
the readme.txt then directs me to copy all these assets to the folder for the noactivity project folder for android studio.
after doing so , I still don't get any response.
So, I try it with a basic activity and manually add all the required XML codes (activity_main,colours,styles,e.t.c) , but still don't see anything.
I know that the skins exported from xd are in the project folder
(Copied values in the projects folder)
but I cant seem to view them on android studio.
Android Studio Window
any help in this issue will be really appreciated.
You have to put those files in the drawables folder inside the res folder, and keep the colors, string into their respective folder in the values folder inside res.

Xamarin Android assets folder not updating when building the solution

I have a Xamarin.Forms app that needs to read data from a json file. I placed the file into the Android assets folder and selected the build action AndroidAssets
Then I try to load the file in MainActivity with Assets.Open(filename) and I get a FileNotFoundException. I deleted the Android and PCL bin folders and tried to build the project again but got the same result. Then I opened the .apk file in WinRar and when I go to the assets folder, the files that I added to the project are not there.
Does anyone have any idea what's the problem here?
Did you set the files as embedded resources from the file properties?
If you not, right click on the file -> Properties -> set as Embedded Resources in Build Action
The problem was with using the "-" character in resource file names. Changed it as suggested by York Shen and it started working as it was supposed to.

Font file not loading on Libgdx Android

I am using the following code to load font in my libgdx project.
BitmapFont(Gdx.files.local("fonts/test.fnt"))
This is working fine when i launch using Desktop Launcher.
however when I launch using Android Launcher i get the following error.
com.badlogic.gdx.utils.GdxRuntimeException: File not found: fonts/test.fnt (Local)
I am not sure What am i doing wrong here. My Android project's assets for folder contains fonts folder and has the files test.fnt and test.png.
On Android, assets can only be accessed using the internal file system:
Gdx.files.internal("filename");
Are you using different assets folders for both desktop and android so that you have separate copies of your files? Or are you using the same assets folder for both desktop and android?
If your are using the same assets folder, then both desktop and android have to use the android assets folder. Android is finicky in this way. So you will have to set your desktop assets folder to point to the android assets folder, then anytime you add new assets you have to add them to the android folder.
This is how I initialize my fonts.
fontTexture = new Texture(Gdx.files.internal("assets/texture/font.tga"));
buttonFont = new BitmapFont(Gdx.files.internal("assets/texture/font.fnt"), new TextureRegion(fontTexture), true);
By using internal it searches your project for the folder containing the assets for me that folder is "assets" my project looks something like this:
Eventhough I clearly have my assets packed into my project, I will get the same error when I export my application just like this.
Now here's how to solve that issue. You need to open up your exported project with something like 7z or Winrar, and manually drop in the 'assets' folder. In your case "fonts". This should should fix it, atleast I always have to do that, it never packs the assets for me.

Not finding Raw floder in eclipse to work with android application

I am android beginer. I wanted to add audio file into my android application. In one of the tutorials i found that audio file need to be added to "RAW"folder but i am not finding such folder in my eclipse indigo version. somebody please tell me, did i delete it by mistake or have i not installed some file?
you should create it yourself, put it in the res folder and name it raw (lower case).
You can do it by two ways:
Right click on res folder and create a folder named raw
Clear / Rebuild your project
Or you can do it manually:
Go throught the workspace projects go to your application / your package name / res / (Then you right click) Create Folder and named it raw.
Restart the IDE and it will appear.

Android studio : Creating a normal xml file in assests folder?

I've been trying to create a normal XML file in Android studio for manual RSS feed but android studio not letting me to create it. I just started using Android studio & migrated from eclipse.
Here's the options for File->New
In fact, it is simple. You need to put "ordinary" xml file inside "raw" folder and you can create it by clicking new->file and setting its name to rss.xml for example.
If you dont have raw folder then right-click on res->new->Android res directory select resource type to raw and click ok

Categories

Resources