Read asset file from an Android module - android

I would like to know how to access the assets directory from android (file path)
I tried something like :
Uri.parse("file:///android_asset/Resources/sound/" + sound);
But it doesn't work !
I know that I could do that easily with Titanium BUT I need the URI file from the JAVA module ...
Any idea ?

No Uri or File class.
You have to use the assets manager and then open an inputstream for your file and read from the stream.

Related

How to use QFile on Android?

I need read .txt file on android using qt program. If build for windows, that file should be in build folder, but what about android? How to include it in apk?
You can include the text file into your APK's assets, and then refer to it like so:
QFile file( "assets:/qml/foo/main.qml" );
This question has another URI for accessing assets: How to add qt resources to android APK file?
Or you can package the QFile in your application as a QRC (http://qt-project.org/doc/qt-5.0/qtcore/resources.html) and access it like so:
QFile file( "qrc:/path/to/file.abc" );
Both of these options are read only.

Can't locate file context.getDir("data", ...) in Android

I have a db located at
ctx.getApplicationContext().getDir("data", 0) + "/" + "db.db4o";
How can I browse this file with an file manager or via USB? I can't seem to find it :<
Browse with file manager, or USB, what does that mean? You can access the data directory, through a file manager, only if you are on a rooted device or an emulator.
Your application specific file are not directly stored in the data directory, but
data/data/your_package_name
you could create an "asset" folder into your android project and put it there. Before that you can try with this:
InputStream is = getAssets().open("db.db4o");
And convert "is" if is necessary.
Regards

Files directory in android

I have a file into "files" directory in my android project in eclipse, but when run the application in my device or in a device emulator, i don't find this directory
i want to put this file in /data/data/MYPACKAGE/files/mifile.txt during the installation
put it under assets folder and use getAssets() to access it
InputStream inputStream = getAssets().open("files/myfile.txt");
this will return the InputStream from the file then you can read it.
You could use getRessourceAsStream(String path) or simply use the assets folder and getAssets()

Bad path trying to open file in Android

I'm trying to open a file with this:
document = builder.parse(new File("Data.xml"));
and I'm getting this message:
/Data.xml: open failed: ENOENT (No such file or directory)
and the file is in the root directory of the android project.
You are trying to open a file located in / (in linux this is the root directory of your file system). Instead you should be trying to create a file either on the SDCard or within the local storage directory for your application.
See this for more clarification: http://developer.android.com/guide/topics/data/data-storage.html
Move Data.xml into the assets folder of your project. Then to get a file reference, call getResources().getAssets().openFd( "Data.xml" )
You should probably try using a file input stream constructor for the builder instead, and use openFileInput( String fileName ) to get that, which does only use your app's data directory.
Using persistent storage
openFileInput()

Adobe Air for Android: Where is a xml file after instalation .apk file

An Air app which loading data from an external XML file (cfg.xml). I've published the Android/Air file, included the cfg.xml file in the Android package. Then I've installed on my SD Card(). App's reading xml file - working perfectly. But I need raw access(on my device) to cfg.xml I cannot find this file, checked everywhere(Rooted Phone). Where is it? Is there other solution? I need a file which is easy to read/write.
Use DDMS -> File Explorer and look for you app name in folders like data, ...
Solution:
Use fileStream instead of URLLoader
Change directory to SD Card e.g.
File.userDirectory.resolvePath("YourAppData/cfg.xml")
(No rooted phone needed)

Categories

Resources