pixelearth
pixelearth

Reputation: 14630

How to refer to a resource not in the Library Project, but only in the dependent Application Project?

I'm turning my one app into several similar apps and using a base library project. I want to load a video that will be in res/raw/welcome.m4a in the dependent applications.

This is how is was being done before using the library project:

vv.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.welcome));

This produces an error in my library project, because res/raw/welcome.m4v doesn't exist, it will only be in the App Project res/ folder, and will be different for each app.

My current workaround is to create a dummy res/raw/welcome.m4v in the base library project so it stops complaining.

So my question is how do I have code in the Library Project that refers to resources that don't exist in the Library Project?

Upvotes: 1

Views: 176

Answers (1)

Femi
Femi

Reputation: 64710

If it is only happening infrequently, you can try this:

vv.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+getResources().getIdentifier("welcome", "raw", getPackageName())));

Not as performant as using the id, but it should work.

Upvotes: 1

Related Questions