An APK file, like a Java JAR file, is really just a ZIP
archive file with special manifest data included with the
other data files.

Your assets/ directory on your development machine may
contain individual files.  They get zipped up into the
APK along with all the .class, .png and .xml files.
The APK file contains it all in one file.

Once inside the APK, there really is no "absolute path"
to the files inside.  They are not really files.  They
are just entries in the ZIP, which a zip expander could
reconstruct into real files later.

This is why you use special API to access assets.  Many
apps ship with initial databases, and if the app finds
no existing file, it uses the special API to reconstruct
real files (sometimes confusingly called "copying a file
out of the APK").

See "copyDataBase()" in this article for a working
example of how to extract an asset and reconstruct a
file in your data directory.

http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

On Jan 27, 2:31 pm, Titus <[email protected]> wrote:
> Hello,
>
> I have been trying to get the absolute path for an asset file but i
> havent found an answer.
>
> the file which is directly within my asset folder is mydemo.txt
>  and i call the function given below to test the validity of the path
> (tried the below options)
>                 testURI("//android_asset/mydemo.txt");
>                 testURI("//assets/mydemo.txt");
>
>         public void testURI(String filepath) {
>                 try {
>                         Log.e(TAG, "Testing " + filepath);
>                         File f = new File(filepath);
>                         if (f.exists() == true) {
>                                 Log.e(TAG, "Valid :" + filepath);
>                         } else {
>                                 Log.e(TAG, "InValid :" + filepath);
>                         }
>                 } catch (Exception e) {
>                         Log.e(TAG, "File not found" + filepath);
>                         e.printStackTrace();
>                 }
>         }
>
> Can someone let me know whats the absolute path i can use to get an
> asset file. i don't need the file descriptors but i want the file path
> to construct an URI.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to