So, I've seen many posts on this, but none has helped. I want to work with the assets folder, for organizational purposes. The images below show where the 'assets' folder is, along with the app.imi options of where it should be. I have tested this, and in the >exploded-aar/com../appcompat-v7/19.1.0/assets ... the files inside this seem to work. I can call on the .mp3 file and load and play it correctly (Though a few times it did not recognize it. Even when it was inside a folder, inside of the directory.)
In the src/main/assets folder, all the files are ignored. Is there a specific way I have to call this? In other words, must I also link the actual folder it is it? src/main/assets/music to load up the riseofcc.mp3?
I do not have 10 reputation to post images, so sorry for only links.
EDIT:Also I am using Android Studio 0.5.7
ANSWERED:
Thanks for Xavier Duchrohet for explaining exploded-aar is for the application's dependencies. I have learned that when calling upon a file inside your asset's folder using the code:
AssetManager assetManager = getAssets();
InputStream inputStream = null;
AssetFileDescriptor descriptor = assetManager.openFd("sound/explosion.ogg");
You must include the folder's parent inside the arguement.
Android Studio's app.iml has the asset's directory (src/main/assets) inside of its configuration's options.
Normally, to include sound files, I create a folder called raw, inside the app / src / main / res.
That is, I right click on the folder res and from the menu that appears, choose: New / Android Resource Diretory. Renaming in the window that appears, the Directory name field values for raw.
How it works for me, I hope this might have helped him.
Related
In Android Studio, I need to use some resources (image, audio, etc...) from a folder different from the standard 'res',
Let's suppose that I have:
the '_Resources' folder containing the image 'aaa.png' .
the standard 'res' folder containing the image 'bbb.png'
I have put inside gradle file:
android {
sourceSets {
main.resources.srcDirs += 'C:/..../myLibrary/src/_Resources'
}
}
After that I see in Android window (top left of Android Studio) correctly both the standard 'res' folder and the 'resources' folder.
if I have to access to 'bbb.png' of 'res' standard folder, I use:
import com.myproject.R
.....
int xxx = R.drawable.bbb
THE QUESTION IS:
how can access now to aaa.png?
It is not seen in R. ; so I tried to import something else, but what?
Thank you in Advance
Fausto
This is not possible. If you define two png file with the same name in multiple resource folders android will load just one of them (not sure which one).
The name of them are actually their ID. And the concept of ID is sensful if its unique. So you cant do this.
Having multiple resource folders is just something to separate files and make everything more clear and better. Just foldering and nothing more.
for those that could have the same problem:
I didn't have success in accessing to resource folder, but I found another solution that fits my needs:
I added the '_Resources' folder in Assets, writing in gradle file:
main.assets.srcDirs += 'C:/..../myLibrary/src/_Resources'
then I get access in code to resources by:
AssetManager assetManager = getAssets();
InputStream myInputStream = assetManager.open("aaa.png");
That's all...
My app depends on 3 different files. I already put the two larger ones as expansion files which seems to work fine. Now I don't know where to put the third one (small file). I tried the raw folder but actually I don't know what the path of the file is once it is in those folders.
I tried this here for the raw folder
myClassifier.loadModel( pathToExpansionFiles + "/File1",
pathToExpansionFiles + "/File2",
R.raw.File3);
However the return value of R.raw.File3 is an integer, but the function myClassifier expects a string that is the path to File3. Has anyone an idea how to do that?
I tried the raw folder but actually I don't know what the path of the file is once it is in those folders.
There is no path to it. That is a file on your development machine. It is not a file on the device. It is merely an entry inside your APK file.
but the function myClassifier expects a string that is the path to File3
Either switch to some library that works with an InputStream (from getResources().openRawResource()) or make a copy of the data to a local file using that InputStream yourself.
I try to use OpenNLP in an Android application with eclipse, and I imported the 4 JARs into the libs folder.
It's probably a stupid question.. but where should I put the model files "en-pos-maxent.bin"? I can't find anything regarding the path anywhere
I try to run the code contains this line:
POSModel model = new POSModelLoader()
.load(new File("en-pos-maxent.bin"));
I tried putting the en-pos-maxent.bin inside a new folder within the project("tagger/en-pos-maxent.bin"), inside the libs folder, or simply give the path where the en-pos-maxent.bin is put when downloaded("Users/ariel/Downloads/en-pos-maxent.bin"), it always give me the error: POS Tagger model file does not exist path: (the path I typed in)
Could anybody help please?
When you use new File("filename") the file is expected to be in the current working directory, I don't think that's different on Android. You can use System.getProperty("user.dir") to get the current working directory. It's by default the directory you start the program from. You could also specify a full path like new File("/full/path/filename") instead.
In android the right way to add file to the application (inside APK) is to put into the assets folder. Then you can't get File object from assets folder but, you can create that File using a buffer or in you case just get it into the InputStream. For example if you will create models folder into the assets folder (assets/models), your code will look like this:
AssetManager am = getAssets();
InputStream inputStream = am.open("models/en-pos-maxent.bin");
POSModel posModel = new POSModel(inputStream);
I wanna include a text file to my project in smartface appstudio. I put it where? In resources folder or assets? FileStream could not read it in resources (as a drawable item). Any idea?
var txtFile = new SMF.IO.FileStream(SMF.IO.applicationResources, "words.txt", SMF.IO.StreamType.read);
txtFile.readToEnd();
It is not implemented in current release of Smartface App Studio. Also I have tried it before. It is Phase 2 for File Operations.
You can download your static text file from the internet and can save it to the local storage. And read it from there. I can just suggest you this idea. Check some helpful links below.
http://developer.smartface.io/hc/en-us/articles/203177557-File-Operations
http://developer.smartface.io/hc/en-us/articles/202153536-File-Download-Upload
I have few html files in assets folder of my application. My application loads these files depending on the device language. When I check for the existance of the file it say does not exist, but when I load that file using browser.loadUrl(filename), it loads it fine.
Following code will help you to understand my problem:
String filename="file:///android_asset/actualfilemname.html";
File f = new File(filename);
if(!f.exist){
filename = "file:///android_asset/newfile.html";[Everytime it loads this file even though I have actualfilename.html in the folder]
}
browser.loadUrl(filename);
[it loads the newfile.html but not actualfilename.html]
You can't use File for resources. You'll need to use the AssetManager for that.
(In the off-chance that File does handle resources, which I don't think it does, you'll have to convert the path to a URI first, for example using URI.create(). File(String) expects a path, not a URI.)
Is this the exact code you are using? you probably want to be calling f.exists() not filename.exist().
Edit: try working with the AssetManager instead of hard coding your file path. My best guess is that the file path you are using is not exactly how it supposed to be.