App access to sdcard while in Eclipse debug?

chasmopolitan

New Member
Joined
Sep 7, 2010
Messages
4
Reaction score
0
Location
Eagle, Idaho
I would like my app to be able to open a file on the sdcard at:
/sdcard//SmartRotor/ExampleZlog.txt

The following method:

public StreamProcessor()
{
System.out.println(filePath);
try {
fileReader = new FileReader( filePath );
} catch (FileNotFoundException e) {
System.err.println(e);
}
bufferedSmartRotorStream = new BufferedReader( fileReader );
}

displays logcat entries:

INFO/System.out(28609): /sdcard//SmartRotor/ExampleZlog.txt
WARN/System.err(28609): java.io.FileNotFoundException: /sdcard/SmartRotor/ExampleZlog.txt

I notice when the DroidX is attached via the USB cable the Android Files manage cannot access the sdcard (probably owing to its being mounted on the laptop). I assume that is the reason I can't open the file from the app.

Is there some incantation I'm missing that would permit
fileReader = new FileReader( filePath );
to an /sdcard/-based file path?

Newbie,
-chas-
 

mwhartman

Super Moderator/RS
Premium Member
Joined
Jan 15, 2010
Messages
10,635
Reaction score
12
Location
South FL
Most of the code you supplied is above my pay grade. I have a rooted Droid and when connected to my computer the SD card can only be accessed via the computer.

Mike
 
OP
chasmopolitan

chasmopolitan

New Member
Joined
Sep 7, 2010
Messages
4
Reaction score
0
Location
Eagle, Idaho
Thanks, Mike. I think that confirms my suspicions that the Eclipse USB-mount makes /sdcard inaccessible from the device. Unless there's some other Linux-like incantation by which the /sdcard can be shared and mounted by both the local and the remote. I guess I'll have to live with that restriction for now.

You wouldn't by any change know how to create an /sdcard location for an Android Virtual Device(VD)?

-chas-
 
OP
chasmopolitan

chasmopolitan

New Member
Joined
Sep 7, 2010
Messages
4
Reaction score
0
Location
Eagle, Idaho
Add directory structure and files to emulator /sdcard

For posterity, here's what worked for me:

On Windows Vista; fire up a command window (I have a desktop shortcut "%SystemRoot%\system32\cmd.exe")
cd "C:\Program Files\android-sdk-windows\tools"
mksdcard -l DroidXcard 500M C:\Users\<user>\.android\avd\Android7.avd\sdcard_v7
Run Eclipse and open project. Then:
Run -> Debug Configurations...->Android Application->"Target"<tab>
You may have to resize the "Debug Configurations" window by dragging the lower border down to expose the "Additional Emulator Command Line Options" field.(!) Enter the file path to the sdcard image:
-sdcard "C:\Users\<user>\.android\avd\Android7.avd\sdcard_v7"
Within Eclipse, Run debug (F11), and go the DDMS view (tab labeled "DDMS" in upper right-hand corner of Eclipse window). In that view find the "File Explorer"<tab> which should show an \sdcard directory. *And* you should be able to enter the directory. If you can't you haven't properly created or loaded the mksdcard image. Note: You'll get cryptic "permission"-related messages.

Terminate Eclipse debug session (<cntl>+F2). This leaves the AVD/emulator running and disconnects Eclipse from it.

Again, from a command window in Windows Vista:
cd C:\Program Files\android-sdk-windows\tools
adb -e shell -- fires up a shell on the emulator
cd sdcard -- puts you in the main directory of the sdcard image you created with mksdcard
mkdir <myProjectDir> -- use to create any directory structure you need
exit -- leave the shell
Run Eclipse again and open project. Run debug (F11), and go the DDMS view. Using the Eclipse DDMS "File Explorer"<tab>, descend to the directory in /sdcard you want. In the upper right-hand corner of the "File Explorer"<tab> find icons for "Pull a file"... and "Push a file".... Use the latter to move a file from your Windows file system into the emulator's \sdcard file space.

There may be better ways, but for this newbie, it worked.
-chas-

P.S. Why go to such lengths when you have a real DroidX? Because when you connect your device via USB, Windows auto-mounts the \sdcard directory depriving your device-resident app of access... <grumble>.
 
Top