Path to SD card's Android/data directory

You must Login before you can answer or comment on any questions.

Hi,

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.

— asked 9 months ago by Onoma Epitheto
5 Comments
  • can you please provide some code, show the files being saved and how the FileSystem calls are not working for you.

    — commented 9 months ago by Aaron Saunders

  • Hi Aaron,

    The thing is I cannot find how to target this path (sdCard/Android/data/com.myapp) with the Filesystem calls. Can you help on that? I would like to target this folder: http://i49.tinypic.com/oqyem0.png

    — commented 9 months ago by Giorgos Papadopoulos

  • I am a colleague of the topic starter btw..

    — commented 9 months ago by Giorgos Papadopoulos

  • Show 2 more comments

1 Answer

Accepted Answer

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 Ti.Filesystem.getExternalStorageDirectory returns 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 Environment.getExternalStorageDirectory().

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.

Post 142255 is related

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.

https://github.com/kenkendk/ti_androidexternalstoragemodule

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.Android of Ti.Filesystem. If there is an easier way to obtain them, please correct me.

— answered 5 months ago by Kenneth Skovhede
answer permalink
8 Comments
  • The most complete answer I have ever seen to a forum question! Thank you Kenneth!

    — commented 5 months ago by Onoma Epitheto

  • Hi Kenneth, I'm facing a similar issue (http://developer.appcelerator.com/question/147339/how-to-correctly-store-files-into-sdcardandroiddata) but, when I install your module an alert pops up stating it is not compatible with my SDK version (I'm using 3.0.0)

    — commented 4 months ago by Kiwi Blas

  • I am using the module in a TI 3.0.0.GA build myself, and I have not had any issues. Are you building yourself, or using the zip?

    In any case, the properties that produce this error are located in the "manifest" file. The apiversion should be 2 and the minsdk should be 2.1.4.GA.

    From what I know, there is no newer version of the API than 2 (introduced in TI 1.8).

    Maybe some of the hints to a similar problem can help you

    — commented 4 months ago by Kenneth Skovhede

  • Show 5 more comments

Your Answer

Think you can help? Login to answer this question!