Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why aren't my asset files updated?

My program opens a .txt file from the assets folder and reads from it. Here is the code:

           AssetManager myAssetManager = myContext.getAssets();
           try{
                   InputStream is = myAssetManager.open("databaseeleven.txt");
                   byte[] bytes = new byte[is.available()];
                   is.read(bytes);
                   commands = new String(bytes);

           } catch(IOException e){
                   Toast.makeText(myContext, e.getMessage(), Toast.LENGTH_SHORT).show();
                   e.printStackTrace();
           }//try-catch

I have noticed that when I make changes to the file called databaseeleven.txt and save the file, my changes aren't reflected on the emulator when I run my program again. The project is saved to a thumb drive. I checked it to make sure there's only one file with that name, and it is up to date. I know the application is re-downloaded because of changes to the code. I'm using egit, Eclipse version 3.6.2, and ADT version 10.0.1. Does anybody know why my program isn't working off this saved file?

Update: Refreshing and then cleaning the project again doesn't help.

like image 341
sthompso Avatar asked Apr 23 '11 06:04

sthompso


People also ask

What does asset file mean?

An Asset Definition file is an optional XML file that you can use to import assets into SiteProtector. The Asset Definition file provides a complete list of information about an asset, including information that you specify in the New Asset window, such as Criticality, Function, and OS version.

How do I view assets files?

To view asset files in Files home, select Libraries and then select Asset Library . To view and edit asset files in Setup, enter Asset Files in the Quick Find box, then select Asset Files. Click the name of a resource to view its details.

What should be in the Assets folder?

Assets provide a way to add arbitrary files like text, XML, HTML, fonts, music, and video in the application. If one tries to add these files as “resources“, Android will treat them into its resource system and you will be unable to get the raw data. If one wants to access data untouched, Assets are one way to do it.

How do I add an asset to my android?

Two ways: Select app/main folder, Right click and select New => Folder => Asset Folder. It will create 'assets' directory in main. Select main folder, Right click and select New => Directory Enter name as 'assets' = > Ok.


3 Answers

If i have understood your problem correctly, you are trying to alter the file in /assets folder. changing .apk contents after signing the package is not possible.

If the file is small, copy it into your app's private data directory.

If the file is bigger, copy it into the /sdcard.

like image 103
Samuel Avatar answered Oct 11 '22 07:10

Samuel


It was happening to me with a .sqlite file in the assets folder and I solved it by

  1. uninstalling the app from the phone
  2. and rebuilding.
like image 29
fersarr Avatar answered Oct 11 '22 07:10

fersarr


What's the file size of databaseeleven.txt?

There is a limit of 1MB per file for the assets file, if the file size exceeds this limit it won't be available in your apk.

If this is your case, there are two alternatives I know of:

  • Split your file into 1MB chunks, you have an example this in this SO question
  • Use a file extension that doesn't get compressed by Android, as suggested here. Note that your file won't be compressed and you will probably end up with a big apk.

NOTE: It seems that the 1MB limit was removed in Android 2.3, so this only applies to 2.2 and lower.

like image 35
aromero Avatar answered Oct 11 '22 06:10

aromero