I cannot find any way to get a reference to the path Android/data, which is located in the sd card of Android. Anybody knows how to get this path with Titanium.Filesystem ? I tried already all the available properties (applicationDataDirectory etc and also manually by Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory, "Android", "data", "com.mydomain.myapp")
This is the path that Android creates for apps that use prefers external true in the android manifest. I would like to use it because I download a lot of images in my app and I want them to be deleted when the user uninstalls the app. This directory is being removed upon uninstall.
From what I can tell, Titanium is not implementing this correctly. From what I can read, you need to call
Context.getExternalFilesDir(), to get that special path. According to the Android documentation, this folder is removed upon uninstall.
In Titanium, the call to use is
Ti.Filesystem.getExternalStorageDirectory(), but this does not entirely equal the Android
Environment.getExternalStorageDirectory(), because Titanium appends the application package name.
This means that
appdata:// which is translated into something like
/storage/sdcard0/com.example.testapp. This can be fine for some uses, where you want to preserve the data between application installs. If you intend the user to find the data, I would argue that you should use your apps displayname rather than the package name. You cannot get the
Context.getExternalFilesDir() path from Titanium. You can discard the package name to get the equivalent of
I would not advise you to rely on backfolding the path to get something like
/storage/sdcard0 and then appending
/Android/data/com.example.testapp, as each Android installation (manufacturer, packager, modder, etc) is free to choose the naming scheme they want.
My only solution to this was to roll a native module that simply provides access to these two system calls. I have made my solution available as a Titanium module, pre-compiled and free of charge.
I really think these two very simple methods should be included as part of Titanium, I would be willing to add them to the source, but I don't know if they should be under
Ti.Filesystem. If there is an easier way to obtain them, please correct me.
Think you can help? Login to answer this question!