Search code examples
androidassetsandroid-library

Read assets file outside library android


I'm creating an Android library and I want developers to be able to provide a configuration file in their Android project.

Is there any way to find and read this file(having a specific name) without having the context of the android project?

Or is there a standard procedure for library configuration files?


Solution

  • Is there any way to find and read this file(having a specific name) without having the context of the android project?

    No, assuming that by "the context of the android project", you mean a Context.

    Or is there a standard procedure for library configuration files?

    Usually, that would be some form of resource, or perhaps an asset. Or nothing at all, instead going with some sort of builder API that the app developer would call.

    If you do not want to deal with Context, accept an InputStream as a parameter to your constructor or initialization method. That gives the app developer the flexibility to use raw resources, assets, internal storage, external storage, or other possible places to have this configuration file.