is accessing a raw resource from within android library possible?
I am writing an android library and am having a problem.
In my library I am attempting to access a file stored in the res/raw
directory of my library project like that:
InputStream inputStream = Resources.getSystem().openRawResource(R.raw.sample);
I've also tried:
InputStream inputStream = mContext.getResources().openRawResource(R.raw.sample);
(where mContext is a reference I've passed from my main app to my library)
However I get an exception file not found
when trying to instantiate my library from 开发者_如何学编程my main project.
Is it possible to actually do this, and if so how do I go about doing it? or do I need to pull in the resource from my main project and send it to the library?
Accesing a raw resource located in some app from your library is bad design.
I suggest opening first the InputStream
in your application, using the second syntax you posted. Then pass the InputStream to your library.
If you finally decide to access the resource from your library, you could try this.
精彩评论