Questions tagged [android-assets]

You can use the `assets` folder to store raw asset files. Files that you save here are compiled into an .apk file as-is, and the original filename is preserved. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes using the the AssetManager. For example, this is a good location for textures and game data.

In Android, you can use assets folder to store raw asset files. Files that you save here are compiled into an .apk file as-is, and the original filename is preserved. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes using the AssetManager. For example, this is a good location for textures and game data.

598 questions
1576
votes
26 answers

Where to place the 'assets' folder in Android Studio?

I am confused about the assets folder. It doesn't come auto-created in Android Studio, and almost all the forums in which this is discussed talk about Eclipse. How can the Assets directory be configured in Android Studio?
Harshad Kale
  • 17,446
  • 7
  • 30
  • 44
291
votes
8 answers

Difference between /res and /assets directories

I know that files in the res directory are accessible from R.class while assets behaves like a file system, but I would like to know, in general, when it's best to use one and the other. Can anyone help me in knowing the real differences between res…
Cris
  • 12,124
  • 27
  • 92
  • 159
166
votes
4 answers

When should I use the assets as opposed to raw resources in Android?

I'm in the mid of my Android studies, and I just covered the Assets and Raw resources. I'm trying to understand the reason for using Raw resources vs. Assets. They both provide with an uncompiled resource input stream. It seems that Assets provide…
Mortalus
  • 10,574
  • 11
  • 67
  • 117
142
votes
6 answers

Play audio file from the assets directory

I have the following code: AssetFileDescriptor afd = getAssets().openFd("AudioFile.mp3"); player = new MediaPlayer(); player.setDataSource(afd.getFileDescriptor()); player.prepare(); player.start(); The problem is that, when I run this code, it…
Catalin Morosan
  • 7,897
  • 11
  • 53
  • 73
93
votes
6 answers

Loading existing .html file with android WebView

I did try samples, demos from Google codes and other resources with WebView, but when i try to do it in my own code, it doesn't work for me. I want to load myfile.html which i put in assets folder, and using: private WebView…
laph
  • 2,925
  • 2
  • 18
  • 18
66
votes
4 answers

How to get the android Path string to a file on Assets folder?

I need to know the string path to a file on assets folder, because I'm using a map API that needs to receive a string path, and my maps must be stored on assets folder This is the code i'm trying: MapView mapView = new MapView(this); …
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
54
votes
7 answers

how to reference an asset in a library project

In a class belonging to a Library project I call: webview.loadUrl("file:///android_asset/info.html", null); Unfortunately, this only works if I duplicate the file info.html into the Application's project asset folder as well. Is there a way to tell…
an00b
  • 11,338
  • 13
  • 64
  • 101
41
votes
3 answers

Read a Text asset(text file from assets folder) as a String in Kotlin (Android)

I need to read a text file stored at src/main/assets/ i.e; in the assets folder and get it as a string. Is there a simple way to do it. Java copy, paste, convert functions are giving trouble, so I'd rather use a kotlin way. I need a kotlin way to do…
Kotlinboy
  • 3,725
  • 4
  • 16
  • 27
38
votes
14 answers

Accessing a font under assets folder from XML file in Android

I am trying to do a application-wide font change and creating a style file to do so. In this file (below) I just want to change typeface value of TextAppearance style of Android.
erkangur
  • 2,048
  • 5
  • 21
  • 31
37
votes
1 answer

WebView on Android ICS, iframe problems with android_assets

My application engine runs inside a WebView. It spans different IFRAMES. Both the main application html and the iframes html are on android_assets. On Android 3.x no problems ever. Same on chrome browser, etc. If I create an IFRAME (createElement ->…
31
votes
9 answers

Android icon generator for actionbar and notification not working (grey shape)

I found this Asset Studio to generate icons. It works fine for the launcher icon but for action bar or notification icons it is not working. I put in my png file and want to generate the icons, but Asset Studio is only generating gray circles. Is…
Mulgard
  • 9,877
  • 34
  • 129
  • 232
31
votes
11 answers

Read a pdf file from assets folder

public void DOCS(View btnDocs) { File fileBrochure = new File("android.resource://com.project.datastructure/assets/abc.pdf"); if (!fileBrochure.exists()) { CopyAssetsbrochure(); } /** PDF reader code */ File…
rick
  • 913
  • 6
  • 13
  • 28
26
votes
5 answers

How to access a file from asset/raw directory

with this below code i'm trying to access the file which is stored in asset/raw folder, but getting null and E/ERR: file:/android_asset/raw/default_book.txt (No such file or directory) error, my code is: private void implementingDefaultBook() { …
DolDurma
  • 15,753
  • 51
  • 198
  • 377
24
votes
6 answers

Set Notification Sound from Assets folder

I am attaching the sound files in the assets folder for play sound in the notification but I am not able to play sound from the assets folder. I have setting page from which user can set the sound for the notification and also user can play sound.…
24
votes
5 answers

Android Media Player: Start called in state 4 error(-38,0)

This is the code am using to fetch a file name(.mp3) dynamically from some other class as am having many mp3 files in my assets folder: playAudioButton.setOnClickListener(new OnClickListener() { @Override public void…
D'yer Mak'er
  • 1,632
  • 5
  • 24
  • 47
1
2 3
39 40