问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/17004739/how-to-refer-to-a-resource-not-in-the-library-project-but-only-in-the-dependent