where is /data/data/? - android

Beginner android question. Ok, I've successfully written files. E.g.
// get the file name
String filename = getResources().getString(R.string.filename);
FileOutputStream toWriteTo;
try {
toWriteTo = openFileOutput(filename, MODE_WORLD_READABLE);
// get the string to write
String toWrite = getResources().getString(R.string.contentstowrite);
toWriteTo.write(toWrite.getBytes());
toWriteTo.close();
...
}
catch (Exception ex) {
Toast.makeText(HelloFilesAppActivity.this, "fail!", Toast.LENGTH_SHORT).show();
}
}});
And I've proved that it is there by reading it and displaying contents, even using getFilesDir() and displaying all of the files in the folder.
Everything I read says that the files are in /data/data//files/
But I cannot find them. (I'm on Windows XP). My install didn't use default locations because my C:\ is pretty full. I looked in C:\Documents and Settings\Mike\.android\avd and in the project folder and in the place I installed the SDK: D:\Program Files\Android\android-sdk-windows. So where is /data/data/ ?
I read that I can use ADB to push and pull files back and forth, but I'm using Eclipse ADT and I'd prefer to use something other than command line. The book I'm using seems to imply that you can use Eclipse but then proceeds to give the command-line commands.
I found info about the Project Explorer in the DDMS, but I don't see the files I have written.
I've been working under the assumption that I might want to create a text file using some other means in Windows that I would read with my App. So if the answer is "why do you want to do this?", that's what I'm after. Eventually a DB probably too (that's in the next chapter :-) ).
Do I have to use the ADB command line?
thanks
Mike

http://developer.android.com/guide/topics/data/data-storage.html
The method your using to get the directory you read/write to:
openFileOutput()
You can save files directly on the device's internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed.
You'll want to save the files your working with to the SD card.
Try this:
getExternalStoragePublicDirectory Example

It's on your phone. Your phone has its own file system. If you are using an emulator, then it's on the emulated file system, which is completely separate from yours. Your only way to access the phone's (or emulator's) file system is via ADB (unless we're talking about the SD card, which however does NOT host /data/data).
Side note - if your phone is not rooted, you won't have access to a lot of stuff on /data/data. I suppose that you are using an emulator, which is "rooted" in the sense that you have full access to its filesystem.

Related

Can't access file in Android External Storage

I'm using Xamarin Forms for a photo capture app and using James' Media Plugin PCL to capture photo using the device camera.
I realize that, for every photo, it creates a file in
/storage/emulated/0/Android/data/com.myapp/files/Pictures
(and I can provide a subdirectory within Pictures folder and the name of the file). What I want to do is delete all these files the next time my app starts up.
Since I'm only focused on the Android version, I've set up a dependency service call to locally delete the file (which I thought was trivial) but for some reasons I simply can NOT find that file programmatically or through ADB shell.
When I plug my device in for USB file transfer on windows computer, I can see the photos I want to delete in
Computer\Moto G (4)\Internal shared storage\Android\data\com.myapp\files\Pictures
But I can't get to these files through code or shell. In code, I'm getting the path through
Forms.Context.GetExternalFilesDir(Android.OS.Environment.DirectoryPictures).AbsolutePath
which gives me the path
/storage/emulated/0/Android/data/com.myapp/files/Pictures
which I think is the path where my files SHOULD be. But it's come up blank. Whether I try System.IO or Java.IO, the directory comes up empty and file.delete() or System.IO.File.Delete(path) doesn't work for me.
tldr; What does
Computer\Moto G (4)\Internal shared storage\Android\data\com.myapp\files\Pictures
translate to in terms of actual physical path in Android OS which we can list from ADB Shell?
What I want to do is delete all these files the next time my app starts up.
Try using the following code, it works fine on my side :
public void DeleteFolder()
{
var path = Forms.Context.GetExternalFilesDir(Android.OS.Environment.DirectoryPictures).AbsolutePath;
Java.IO.File directory = new Java.IO.File(path);
if (directory.IsDirectory)
{
foreach (Java.IO.File child in directory.ListFiles())
{
deleteRecursive(child);
}
}
directory.Delete();
}
It was a false negative. I was looking at the files through Windows Explorer and for some reason, Windows kept showing me those files even after they were deleted. Obviously, the reason I couldn't se those files through ADB Shell or from within Android File Manager was because those files were never there.
Forms.Context.GetExternalFilesDir(Android.OS.Environment.DirectoryPictures).AbsolutePath
gives me
/storage/emulated/0/Android/data/com.myapp/files/Pictures
which is the same as
Computer\Moto G (4)\Internal shared storage\Android\data\com.myapp\files\Pictures
Both System.IO.File.Delete(path) and new Java.IO.File(dir, children[i]).Delete(); methods work fine. It's just that windows chooses to keep showing the empty "ghost" files.
This issue has apparently been raised before to no answer: Programatically deleted files still show up in Windows Explorer

When using emulators, how to interpret the output path when calling Context.getFilesDir()?

Inside onCreate() I have this line:
File aux = context.getFilesDir();
which outputs this:
/data/user/0/com.example.tirengarfio.myapplication/files
but.. where is this path exactly insde Linux filesystem? or is it taking as reference the Android Studio Project root directory? os should I create it somewhere?
EDIT:
As I said to #Simas, but by the moment Im not connecting any smartphone. Im just using emulators on Linux. My intention is just reading a file using
FileOutputStream fos = openFileInput(FILENAME, Context.MODE_PRIVATE);.
So, where should I place the file inside the Linux filesystem?
This is the path of your app's local data folder. It can either be in the memory card or the device storage.
There's no easy way to access it if your device is not rooted but here's a starter:How to access data/data folder in Android device?
Let us see what the doc says :
Returns the absolute path to the directory on the filesystem where files created with openFileOutput(String, int) are stored.
No permissions are required to read or write to the returned path, since this path is internal storage.
So actually the files you will find are those which were saved with the very same function openFileOutput(String,int) by your/other applications.
So basically if you want to test some functionality (which I suppose) write a unit test that uses this API openFileOutput(String,int) to store some mockup data and then get it again with Context.getFilesDir() and some code for file processing.

How does Android File Storage Work?

I am working on a project that needs to store some .txt to android, and get it from the computer for other use. From what I read from the documentation, I know that there are two types of storage: 1 Internal, which is somewhere deep in the phone that is private to the app. 2 External, which includes the SD card and the Internal Storage of the phone. I want to store it to External->Internal, and I am using this line of code to do that:
public String WalkDir = android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/Walks/";
When I logged WalkDir, LogCat says "/storage/emulated/0", I stopped the app, checked with the adb shell, and there is no folder "0" but "legacy". I unplugged the phone and plugged it back in, the "Walks" folder is now in the root directory, and I don't need adb shell to access it.
So my question is, can you help explain how this system works? Why did "0" disappear? What is "legacy"? Why is the file in Internal Storage when I unplug&plug it?
Thank you very much!
Those are what in Linux are called symlinks (like shortcuts in Windows) that various system apps in Android are using..
/storage, /sdcard are sym linked folders,that means when you open one of those, it redirects to the original(/data/media/0), as for the 0 is just a multi user feature implemented in android 4.2, but only enabled on tablet androids.
Why do this Sym-Link?: simple so it dosent break apps(not only file explorer type of app, but all apps).
Still dont get, why it would break?.Simple. android api have lots of ways to write/read files from folders, u can do manually,u can get the data path, u can get the sdcard path, etc,etc. so to not break that they just does these sym links, thats why in one app the storage contentents are listed on /sdcard but on others, is /storage, etc,etc. one example of an app that broke because of these changes to android is titanium backup, u need to change the internal storage on it, so it work.
2 mount points pointing to the same storage device and partition.
If you create something in one folder, it will show up in the other. Same applies for deleting stuff.
They do not take away more storage space, as it is only available once but shown twice.
You also don't need to worry about it in any way because file browsers normally set their default directory to one of these locations.
As far as i know, Google changed the mount points in Android 4.2 to /storage/emulated/0/ due to them switching to MTP and EXT4(?) for the sdcard. The other mount points are still there for compatibility.

Download file to phone with and without sdcard

I am novice programming android. I want to write a simple application that gets updated. For this I use a simple function that can download a file and show the current progress in a ProgressDialog and I store the file in the phone´s Sdcard like this:
output = new FileOutputStream("/sdcard/file_name.extension");
It would be some problem with the phones that not have SdCard? How can I solve it to work in any phone? Thank you.
There is an internal storage in Android devices, so you can utilize that.
I think, the default path to a private storage is "/data/data/package_name/files/file_name.extension".
Try this code:
FileOutputStream fOut = openFileOutput("file name here", MODE_WORLD_READABLE);
String str = "data";
fOut.write(str.getBytes());
fOut.close();
For further information, look this resources:
Section "Save a File on Internal Storage" of the official Android documentation;
http://www.tutorialspoint.com/android/android_internal_storage.htm
It's not only dealing with the problem phones without SDCard MMC, you'll find phones running without AOSP distribution. In fact, I saw some non-official Android mods (a lot of Chinese phones sold over the world) and you get no guarantee to find /sdcard filesystem in all of them.
If you got root permissions (rooted phone) you can program your app to read fstab and find out which storage filesystem is mounted at.
So, without knowing what Android distribution will run your app, I can tell you I found /data directory at all distros I saw.
Hope it helps.
Regards

how can I copy files to the file system of android?

How can I copy files to the file system (place) in android? How can I access it?
copy files from android to local
adb pull /data/data/com.example.sample ./sample/
copy file to android from local
adb push ./sample/ /sdcard/sample/
I'm not sure if this is what you're asking, but here's another interpretation of your question:
You can place files in the assets folder in the project on your development machine. They will be bundled into the apk file and then access them through the AssetManager class. Something like this from within a Service or Activity class:
AssetManager am = getAssets();
InputStream is = am.open("filename");
This will allow you to read the contents of those files. I don't believe you can write to them though. There are other options for if you need to read and write files in your application's storage sandbox. This is done by calling openFileOutput(). I should note though that the user can always access the files on the device through ddms but other applications won't be able to access files stored in your application's storage sandbox.
Edit Based on your comment, you probably want to use
OutputStream out = openFileOutput("outfile");
to write to a file from your code. This code must be called from within an Activity or Service (something that extends Context). This file will be stored on the phone's file system and not on the sdcard. These files will not be accessible to the average user. If users know how to enable usb debugging then they will be able to access them and there is really no way around this.
You can use:
Environment.getExternalStorageDirectory()
That will give you /sdcard if your device has an sdcard, or something different in other cases. For example the Archos.
I took some time to research about android's system files earlier, but almost always with android x86, i found out that the /system folder inside android is read-only,
it is an image with format is SFS format, this is read-only image format of linux so i don't think you can copy some thing inside this folder. I not sure about rooted android. Hope it will help you.
You can probably hide your file in the sdcard by prefixing it with a dot (ex: .myfile)

Categories

Resources