Reputation: 25414
I'm completely new in Android.
I thought, it would be straightforward, but it's a hell...
I'm using Android Studio 1.2.2, have an app module in it and assets folder under app/src/main/assets which is a default location for it. I put some images there like "img.png" for example. I've set Instrumented Unit Tests according to instructions from android's site. It works. I've got even an instance of Context, which I'm taking in this way: InstrumentationRegistry.getContext()
. Then I'm obtaining an AssetManager: context.getAssets()
. So far so good. But all fails when I'm trying to get my "img.png" using assetManager.open("img.png")
. It throws file not found exception. I used assetManager.list("")
method to see what's in assets folder and it returned some unwanted, trash directories like "images", "sounds", "webkit". I don't have them in my assets folder. I want my images! Seems that people don't have such issue. Maybe it is related to AVD.
How to make AssetManager to return my assets?
Upvotes: 3
Views: 551
Reputation: 25414
Found it!
I had to replace InstrumentationRegistry.getContext()
with InstrumentationRegistry.getTargetContext()
. Now I still see "images", "sounds", "webkit" but there are also my images.
Upvotes: 1