• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps File structure

ert304

Newbie
I am developing an app which I am porting from IPhone and have just started on the phone. I am having some challenges with the file system.
For a test, I have tried to write a small file from the app and then find it from Windows file manager. I am not having any luck. I have tried:

Environment.getDataDirectory().getAbsolutePath()
Environment.getDataDirectory()
"/Card/Appname/Settings"

with no luck. What am I missing? The data directory just comes in as /data. I am running in debug from Android Studio if that makes any difference. I will be using directories for settings, images and a few more things, so I am planning on my own little tree.
 
So to clarify, are you trying to find the file on your Windows filesystem?
This file won't be anywhere on the Windows filesystem, it will have been created on the device's internal storage. To see the file you need to connect to the device using ADB (Android Debug Bridge)
The command you need is

adb shell

This opens a command shell on the target device, which will allow you to navigate the device's filesystem, and see your files in /data

http://stackoverflow.com/questions/17334336/how-to-open-adb-and-use-it-to-send-commands
http://www.droidforums.net/threads/how-to-adb-for-windows-made-easy.10924/
 
The phone is connected to the PC via USB, I still can't see the file system? File manager shows me 2 folders, Card and Phone. What I am really trying to achieve is to copy a file holding configuration settings generated for that phone by a windows app into the phone's file system in a location where my Android app can read them. I just have no idea where would be a good location on the Android to put that file.
 
File System again
I’m running ADB SHELL, as advised. I’m not seeing much of a change: for example, a ‘ls’ of /sdcard/android/data shows me exactly the same as windows file manager’s view of Phone/Android/Data (phone internal storage). I haven’t found the SDcard I installed yet.

So, the problem still remains: where in the file structure do I put data for my phone app? I am guessing /sdcard/android/data/com.myid.myapp (which has not been created yet by the debug via Android Studio).

I’m going to do a few ADB mkdir’s and see how that affects things.

Any more clues out there?


Ed
 
Please post the code you are using to write the file, enclosed in [code][/code] tags.
 
And call getExternalStorageDirectory() to get the SD card directory.
 
File System

I used JPEG’s to show debug info from a run:

upload_2016-5-12_12-54-0.png


upload_2016-5-12_12-54-21.png


I tried to look at /data/local but had no access, will work on that. No sure how to access it from PC directly.


Ed
 
ls data
opendir failed, Permission denied
1|shell@android:/ $ cd \data
cd \data
shell@android:/data $ ls
ls
opendir failed, Permission denied
255|shell@android:/data $
 
Typically, the /data partition is protected from reading/writing via an app unless you are rooted (excepting /data/media (i.e., the "SD card" for devices that emulate external storage there).

Your app will, of course, have access to it's own /data/data/<packagename> (i.e., $HOME) folder, but access to other /data areas are restricted.
 
I left out the -l, but same difference.

I think I need to use the SDCard to get around this without going Root, which I am not willing to do.
 
Thanks for the help!
I got an answer! Not the one I expected, but I’ve been in the business too long to even be surprised about that.

From the PC, I see 2 directories on the phone (Windows file manager), Phone and Card.

getExternalStorageDirectory() gets me thePhone (phone’s internal ‘SD card’ rather than the one I plugged in) directory. I had put a copy of my test file in that directory from the PC end (I know, way too high, I’ll be moving it down real soon) and I managed to find it in an Android listFiles call. I also managed to read the first record (that’s all I wrote the code for at this time).

upload_2016-5-12_14-17-7.png


So I have got something that works! I haven’t found the external SD card yet. Maybe it is storage/emulated/1? I’ll try that next, but in the meantime, I’m on my way, thanks!


Ed
 
Great to hear, Ed! :)

The "external SD card" is a bit of a rabbit hole, though...hopefuly @LV426 has some better/helpful suggestions re. that--it's a bit of a fuzzy bunny, IMO, and there's not much consensus re. how to define/find/identify it (although you'll find a lot of comments/opinions/suggestions from stackoverflow, etc. that might help).
 
Can't really add much, as I've not had to use external storage myself. But not every device has one, so I'm not surprised there's a bit of confusion there, and it probably varies between devices. In the past, plain old internal storage has served my purposes.
 
Back
Top Bottom