Wednesday, September 10, 2014

Android asset folder

http://android-er.blogspot.com/2013/11/assets-folder-in-android-studio.html

assets folder in Android Studio

Android Studio is a new Android development environment based on IntelliJ IDEA, Gradle-based build support. It have different project structure.

In Eclipse, assets is in /assets folder under your project. In Android Studio, it is in /src/main/assets. In both Eclipse and Android Studio, /assets have the same level of /res folder.

Compare with the exercise of "Embed html using Google Maps JavaScript API v3 in Android App", where /assets/simplemap.html is a asset file of HTML. In Android Studio, it in /src/main/assets/simplemap.html. In both case, it can be accessed with "file:///android_asset/simplemap.html".

assets folder in Android Studio

Note to everyone, you have to use AssetManager with this approach. If you're trying to use asset URIs to later replace with http:// in ImageView.setImageUri, that approach will not work (note: You should download images in a background thread, rather than using ImageView.setImageUri unless performance is not a concern). Otherwise, for Android 2.2 ImageView supports URIs but they have to be in android.resource form. So for images, you have to put them in the res/raw folder if you aren't going to use AssetManager directly and then the URL android.resource://[package name]/" + R.raw.id ... From http://androidbook.blogspot.com/2009/08/referring-to-android-resources-using.html :
"android.resource://[package]/[res type]/[res name]"

Uri path = Uri.parse("android.resource://com.androidbook.samplevideo/raw/myvideo");

No comments:

Post a Comment