0

I just want the path of the assets directory which I want to use as a variable throughout my app.

I know we can refer a file in the "assets" directory using AssetManager, but I don't want to refer a file as of now, I just want the path of the assets directory.

Can anybody help me with this?

4
  • Are you using this to form content Uris? What specifically is your use case? Commented Jul 13, 2011 at 12:52
  • @David: Since android has a file size restriction on files inside raw directory, I will be placing my files in assets directory, and during runtime, I would be retrieving them as need... So basically, the filename would be sort of dynamic, but the path of assets directory would remain same... So want to get the path of assets directory. Commented Jul 13, 2011 at 12:56
  • Understood - I can give you the path in the form of a Uri that you can use with ContentProviders, if that is what you need? Obviously this only works if you use a ContentProvider to load the asset, which is why I ask. Commented Jul 13, 2011 at 13:09
  • @David: I am not sure if that will work or not, but I can give it a try. Actually, I'll be setting the path for the assets directory in one of my custome Settings class, which will be used by other API calls... Do you see this is possible... May be you can share some code which you thing may work, and I'll give it a shot... Thanks in advance. Commented Jul 14, 2011 at 5:57

2 Answers 2

4

I just want the path of the assets directory which I want to use as a variable throughout my app.

There is no "path of the assets directory" on the device.

I know we can refer a file in the "assets" directory using AssetManager, but I don't want to refer a file as of now, I just want the path of the assets directory.

There is no "path of the assets directory" on the device.

Can anybody help me with this?

No, because there is no "path of the assets directory" on the device. Please use AssetManager to retrieve an InputStream to your assets as needed.

Since android has a file size restriction on files inside raw directory, I will be placing my files in assets directory, and during runtime, I would be retrieving them as need

The "restriction" is the same for assets, AFAIK. The usual way to circumvent the "restriction" is to give the file an extension that Android's build tools will not try to compress (.mp3 works IIRC).

Sign up to request clarification or add additional context in comments.

4 Comments

I have been a great fan of your books. I am actually developing a jar file which will is planned to be used in Android project(s). I am aware that the file size restriction can be overcomed by using extensions for files (like .jpg, .mp3, etc) which aren't compressed by Android... I want something like, the user places a certain file(s) in the assets directory and can use it later through API calls exposed by my jar file.. Is my approach correct? If no, do you think there is an alternative which could be better option?
"I want something like, the user places a certain file(s) in the assets directory and can use it later through API calls exposed by my jar file.. Is my approach correct? " -- so long as you get a Context so you can get an AssetManager, that sounds fine. I worry a bit about designs like this that might impose artificial restrictions on the reuser (e.g., you mandating certain file names or directories in assets/). "I have been a great fan of your books" -- thanks!
@CommansWare: accepting your answer.. Lastly, just want an opinion from you: Do you see any possible way in which I can enable the user(s) of my jar file to place files in a certain location, which can be later referenced in their app code to use feature / functionalities provided by my jar file? Thanks in advance!
@mahi: I am afraid that I do not understand that last question.
0

Try using

AssetFileDescriptor

2 Comments

Can you please point me to a relevant link as to how to use it or some sample code...? Thanks in advance
I saw the documentation for AssetFileDescriptor, and I think it does not, in any way, provide the path for the assets directory...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.