How can I edit the text files in assets folder in Android?
Writing into /assets directory at runtime? AFAIK that’s not possible. You can put the original file in /assets, and at the first application run copy it over to the /sdcard.
Writing into /assets directory at runtime? AFAIK that’s not possible. You can put the original file in /assets, and at the first application run copy it over to the /sdcard.
These Lines are working perfectly– InputStream assetInStream=null; try { assetInStream=getAssets().open(“icon.png”); Bitmap bit=BitmapFactory.decodeStream(assetInStream); img.setImageBitmap(bit); } catch (IOException e) { e.printStackTrace(); } finally { if(assetInStream!=null) assetInStream.close(); } If your image is very big then you should scale your image before decoding it into Bitmap. See How to display large image efficiently
Place your text file in the /assets directory under the Android project and use AssetManager class as follows to access it. AssetManager am = context.getAssets(); InputStream is = am.open(“default_book.txt”); Or you can also put the file in the /res/raw directory, from where the file can be accessed by an id as follows InputStream is = … Read more
This answer is out of date, the gradle build system and AAR files support assets. From the Android Docs: Library projects cannot include raw assets The tools do not support the use of raw asset files (saved in the assets/ directory) in a library project. Any asset resources used by an application must be stored … Read more
AFAIK the files in the assets directory don’t get unpacked. Instead, they are read directly from the APK (ZIP) file. So, you really can’t make stuff that expects a file accept an asset ‘file’. Instead, you’ll have to extract the asset and write it to a seperate file, like Dumitru suggests: File f = new … Read more
The main differences between the raw folder and the assets folder. Since raw is a subfolder of Resources (res), Android will automatically generate an ID for any file located inside it. This ID is then stored in the R class that will act as a reference to a file, meaning it can be easily accessed … Read more
ok, that was my very stupid mistake. I post the answer here just in case someone has the same problem. The correct path for files stored in assets folder is file:///android_asset/* (with no “s” for assets folder which i was always thinking it must have a “s”). And, mWebView.loadUrl(“file:///android_asset/myfile.html”); works under all API levels. I … Read more
With resources, there’s built-in support for providing alternatives for different languages, OS versions, screen orientations, etc., as described here. None of that is available with assets. Also, many parts of the API support the use of resource identifiers. Finally, the names of the resources are turned into constant field names that are checked at compile … Read more
player.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength()); Your version would work if you had only one file in the assets directory. The asset directory contents are not actually ‘real files’ on disk. All of them are put together one after another. So, if you do not specify where to start and how many bytes to read, the player will read up … Read more
Try this public class SampleActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); CopyReadAssets(); } private void CopyReadAssets() { AssetManager assetManager = getAssets(); InputStream in = null; OutputStream out = null; File file = new File(getFilesDir(), “abc.pdf”); try { in = assetManager.open(“abc.pdf”); out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE); copyFile(in, out); in.close(); in = null; … Read more