如何在Android中使用assets资源

如何使用assets资源?代码如下:

AssetManager assets = getAssets();
InputStream stream = assets.open( "test.txt" );

这样看来只能在Activity类中使用。如果在别的类中使用这段代码,系统就会报错getAssets不是这个类中的一个方法。
如何在其他的类中使用assets资源.

你可以在你要建立的类中添加上你的构造方法,在你创建这个对象的时候传入context:`

public class Test {
    Context context ; 
    public Test(Context context) {
        // TODO Auto-generated constructor stub
        this.context = context;
    }
    public void getGetAssets(){
        context.getAssets();
    }
}`