Wednesday, April 17, 2013

[android help] how to access resources in a android library project


I am building an android library project which need some static resources(images/xml and etc) internally.


Then I wonder where I can put these resources and how to access them?


Since I put the resources in the assets folder. And I use the AssetManager to access the resources:



AssetManager am = Resources.getSystem().getAssets();
InputStream is;
try {
is = am.open("t.jpg");
Drawable dw = Drawable.createFromStream(is, null);
Bitmap bm = ((BitmapDrawable) dw).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, stream);
} catch (IOException e) {
e.printStackTrace();
}


However I got the error: W/System.err(19583): java.io.FileNotFoundException: t.jpg


What is the problem?



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...