开发者

is accessing a raw resource from within android library possible?

开发者 https://www.devze.com 2023-04-10 20:07 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消