本文介绍了如何引用的资源不是在图书馆计划,但只有在相关的应用程序项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把我的一个应用分成几个类似的应用程序和使用的基础库项目。我想要加载,将在 RES /生/在相关应用程序welcome.m4a 视频。

这是如何正在使用的库项目之前完成的:

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

这将产生一个错误在我的图书馆项目,因为 RES /生/ welcome.m4v 不存在,它只会在App项目 RES / 文件夹,将是每个应用程序不同。

我目前的解决办法是这样它停止抱怨建立在基础库项目虚设 RES /生/ welcome.m4v

所以我的问题是我怎么在这指的是不要在图书馆项目中存在的资源库项目code?


解决方案

如果它只是偶尔发生,你可以试试这个:

<$p$p><$c$c>vv.setVideoURI(Uri.parse(\"android.resource://\"+getPackageName()+\"/\"+getResources().getIdentifier(\"welcome\", 原始,getPackageName())));

还不如高性能与使用ID,但它应该工作。

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?

解决方案

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.

这篇关于如何引用的资源不是在图书馆计划,但只有在相关的应用程序项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:19