Android file explorer - Eclipse - android

I am saving data internally to the phone in Eclipse, and I was told the file that it was saving to was located here. I try to open the file by double-clicking it to see the saved data, but nothing comes up. What am I doing wrong?
I am trying to check that it is saving to the file properly. I am trying to verify that it is saving the text here since I am not sure where else it is saving it.
I have tried pulling it, and saving it to my desktop, but all I get is this error:
Failed to pull selection
(null)

The DDMS file explorer LOOKS like a windows file explorer, and so you think you should just click on things and drag them around and so on.
Unfortunately, it isn't. It LOOKS like that but it IS NOT that.
From the Using DDMS page we find:
To work with an emulator or device's file system:
In the Devices tab, select the emulator that you want to view the file system for.
To copy a file from the device, locate the file in the File Explorer and click the Pull file button.
To copy a file to the device, click the Push file button on the File Explorer tab.
Which is to say, you have to use the buttons to copy the file off the phone on to your local filesystem. From there you can read it using all the double clicking and dragging you are used to.

I'm guessing you viewing the file from the file explorer in the DDMS. Once you located the file there's a couple buttons on the top right corner to pull/push files from the device

Pulling the file from the device via the File Explorer is the correct way. Not sure why is it failing. Real phone or emulator?
There's another way though. There's a program called ADB in the Android SDK; it's under platform-tools. Run it with the following parameters:
adb shell cat /data/data/com.mypackage/files/textfile.txt
The package name will vary, obviously. This will print the file contents to the standard output.
EDIT:
Press Windows key+R.
Type "cmd", click OK.
Type or paste the following line:
C:\android-sdk-windows\platform-tools\adb shell cat /data/data/com.mypackage/files/textfile.txt
replacing the com.mypackage name with the name of your app's package, which I cannot possibly know. Also replace the path to the Android SDK, if needed.
Press Enter.
Watch the output.
EDIT2: by the way, are you closing the stream after writing the data? That could be the reason you could not pull the file via the File Explorer.

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

Android: viewing files from Windows explorer

I have just made an application that uses a SQLite database, and I finally managed to export the database file onto the computer without having to root the Android device. The method I am using is mostly from code I found on various Stack Overflow question/answers. I am basically saving the database file to the public Download folder.
When I look on the Android device using a file explorer, I can see the correct SQLite file in the correct folder (Download folder). However, when I open up the same folder in Windows Explorer from my PC, I can not see the file in the exact same folder.
Now here is the strangest part: When I copy or move the file (using the Android device), even if I am copying and/or moving the file TO THE EXACT SAME SPOT, as soon as I have finished doing this the file instantly becomes visible in Windows Explorer.
I do not want the user to have to do this manually every time, so does anyone know of any way to make sure that the file will be visible right away? Thank you in advance!
Things I have tried so far:
Show hidden files and folders in Windows Explorer
Programmatically moving the file to a new folder within the application itself (the move to the new folder works, but the file still remains invisible in Windows Explorer until manually moving/copying the file again)
Searched StackOverflow for similar issues and have been unsuccessful.
And if anyone wants to see some of my code, let me know and I will post it, but I am thinking that this is less to do with my code and more to do with Android/Windows interaction. And this is where I got my move folder function from: stackoverflow.com/questions/4178168/how-to-programmatically-move-copy-and-delete-files-and-directories-on-sd
Thank you!
I had a similar issue and it was not visible in Windows because I hadn't given it a file extension.
Give it a file extension if you haven't already.

Move an entire folder from windows to Android emulator

Is it possible to move an entire folder as is from windows to an android emulator? - I am sure the answer to this exists somewhere but I am not able to find it. I can move one file at a time either via adb command line or via ddms but neither gives me the option to move entire folder with multiple folders and files inside and when I try to it gives me this error
C:\>adb push C:\Users\peng-lp-10\Desktop\ABC\ /mnt/sdcard/ABC/
cannot stat 'C:\Users\peng-lp-10\Desktop\ABC\': No such file or direct
ory
even if the folder exists.
Look at this question,furikuretsu says:
you can simply drag any sets of files and folders to File Explorer (a window in DDMS perspective). No
need of using arrow icons.
It works fine.

Unable to see file in Windows Explorer while it is visible in Android file browser

Through my Android program I wrote a file like this:
String file = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Files/hello.txt";
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
writer.write(str+"\n"); \\yeah string has a value there
writer.close();
Now when I go to Android's "Astro" File browser, I can see the file hello.txt in /mnt/sdcard/Files but when I mount the sdcard in Windows, I can only see 4 other files which were there in that folder but not hello.txt.
In Windows itself, I even tried to uncheck the hide hidden files option just to ensure that the file is not hidden but it's just not visible.
I even tried to write the file in root of the sdcard but again same problem. Now I'm surprised that how is it possible that I can see the file in Android but not in Windows. In Android I've even checked the file contents and everything looks fine.
What could be the problem? Is the way I'm writing the file wrong?
PS: yes the Manifest permission android.permission.WRITE_EXTERNAL_STORAGE is added.
Ok, I figured out why it was happening.
Actually even if we press "Back" button, the program keeps running and unless I go to Settings > Applications > Manage Applications > "Force Stop" <application> I can't access the file written by this program even if it is on sd card and even if the filewriter has been closed.
This is just based on my observation and I'd like someone to post a better answer with facts and with solution.
edit: I'll update my question accordingly.
edit: as recommended on meta I've posted a new question
Can't see a file in Windows written by an android app on sd-card unless I “Force Close” the app
If worse comes to worst disconnect, reboot and reconnect your Android device. The files should show up then.
I have found a workaround.
I wrote a routine to capture data from the phone accelerometer. I noticed if the file had a .dat or .txt extension I could not see it and could not copy it to my PC.
By not assigning a file extension to the file on the Android side, I found it would be visible from the PC. After copying it to the PC and adding a .txt extension, it could then be viewed on the PC.
To display hidden files and folders
Open Folder Options in Control Panel
Click Start, and then click Control Panel.
Click Appearance and Themes, and then click Folder Options.
On the View tab, under Hidden files and folders, click Show hidden files and folders.

"No media found". How to insert image in android

I am new to android programming so I will be really grateful if someone helps me.
I am trying to implement steganography in android but my problem is I don't know how to insert images in android. Because of which I am getting "No media found". Please help me with this.
I tried
c:> adb push c:\image1.png /sdcard/image1.png
But I get this in the Command Prompt.
failed to copy 'c:\image1.png' to 'sdcard/image1.png' : Read-only file system
I had the same problem, so in case anyone lands on this page here is how I solved it
When creating the emulator device (I use IntelliJ IDEA) - do not forget to move the radio button on SDCard option to the Size option, and specify the needed size, this way a new SDCard will be created and mounted to the emulator. In eclipse there are some command line parameters you can pass (or something else, I am not sure, since I read it only on the stackoverflow).
After that I stopped receiving the "Read-only file system" error, but I tried and tried and tried copying the files to the sdcard using:
adb push image.jpg /sdcard/image.jpg
or
adb push image.jpg /mnt/sdcard/image.jpg
but was receiving "No media found" error in my app or when I went to the gallery.
So I went to Dev Tools on the emulator applications, then to the Media Scanner. It quickly scanned the sdcard, and boom - I finally got to see my images.
Hope this helps :)
The correct directory for my emulator is mnt/sdcard. This works for me:
adb push README mnt/sdcard
Also note that you can explore directories using adb shell ls <path>, which might have tipped you off to the right path.
Edit - apparently sdcard is a symlink to mnt/sdcard and works for me as well. Using a file named image1.png is also working. Maybe there is a problematic file already located at that location for you?
Edit 2 - I think you also need to have the USB mounting option turned off when you use adb to push files. It sounds like you have this on given your comment about the gallery not finding your media.

Categories

Resources