I am trying to programmatically load a .png file but I am not sure what is the exact path I should be giving. I tried different paths that I think would get me to the resource but all return null:
InputStream is = getClass().getClassLoader().getResourceAsStream("playstore.png");
Bitmap bmp = BitmapFactory.decodeStream(is);
mStoreImage.setImageBitmap(bmp);
If I understand correctly I cannot use resources as I am building a .jar. This is my project package structure displayed with Android Studio:
You should use Resources.openRawResource()
e.g. if your Activity
getResources().openRawResource(R.raw.playstore.png);
remember to put the file under res/raw
Edit:
In addition, android has it own method to get drawable (e.g. a png file) into Bitmap
Android Studio Gradle projects read files from a separate resources directory in the same way as Maven does it.
Create a "resources" folder in Windows Explorer (Android Studio don't allow you to do that) and then recreate the package path and place files there, e.g.:
A class located at this path:
C:\...\app\src\main\java\com\adscendmedia\videosdk\AdscnedAPI.java
Read resource files from this path:
C:\...\app\src\main\resources\com\adscendmedia\videosdk\playstore.png
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With