[Q] SD Card full path - Android Software Development

I am trying to load an image into an imageview, using a URI to a file on the SD card, e.g.
Code:
Uri uri = Uri.parse("file:/sdcard/myapp/mysubfolder/myimage.jpg");
imgView.setImageURI(uri);
and on my HTC Wildfire/Android 2.2 it works OK. But I have been testing with several AVD's & using the Eclipse DDMS Perspective File Explorer, I can see that the SD Card does not always appear to be rooted in the same place, e.g.
Code:
/sdcard/myapp....
or
Code:
/mnt/sdcard/myapp....
Can anyone explain why this is happening ? Should I code to test for the path existing & then use the right one ?
Thanks.

Yes, the different paths by different manufacturers is an annoyance.
Luckily, there is something that should help:
Environment.getExternalStorageDirectory().getPath()

That worked a treat. Thanks for the tip.

Related

Cold boot auto install

How would I go about performing an automatic installation of several .CAB files after a cold boot of the XDA 2? These CAB files will be located on a storage card and are part of a commercial package.
Thanks
Tony Hudson
One can create a "autorun.exe" in a folder called "2577" on the memorycard..
But I'm really not sure how...
you can auto install
by putting the updates in the extented rom
http://wiki.xda-developers.com/index.php?pagename=ER2003Edit
not sure how you would go about making them be able to be located on the sd card unless you put in a program in the extented rom
which would again auto install the cab files located on the sd card
I have wrote an eVC app for installing multiple .CAB files on an SD card. I am wanting the CAB files to be installed synchronously then the device to be warm booted so I am calling ShellExecuteEx to open the CAB file, WaitForSingleObject to determine when the CAB file has finished and then KernelIoControl to reboot the device.
The problem is that WaitForSingleObject is returning before the CAB file has closed with an error code of 6 which is invalid handle.
info.cbSize = sizeof(info);
info.fMask = SEE_MASK_FLAG_NO_UI;
info.hwnd = NULL;
info.lpVerb = _T("open");
info.lpFile = (LPCWSTR) &szCAB;
info.lpParameters = _T("");
info.lpDirectory = _T("");
info.nShow = SW_SHOW;
// Call to perform an action
ShellExecuteEx(&info);
if ((long)info.hInstApp > 32)
{
dwRetVal = WaitForSingleObject(info.hProcess, INFINITE);
switch(dwRetVal)
{
case WAIT_ABANDONED:
iErrCode = 4;
break;
case WAIT_OBJECT_0:
iErrCode = 4;
break;
case WAIT_FAILED:
dwErr = GetLastError();
iErrCode = 4;
break;
default:
iErrCode = 0;
break;
}
}
When running this in debug mode the CAB file being executed has presented the user with a dialog box prompting to overwrite existing files and the WaitForSingleObject has already returned.
Any suggestions?
Thanks.
Install From Storage Card on Insertion
This details info about autoinstalls from a SD card...
But the application is also uninstalled on removal of the card?
http://msdn.microsoft.com/library/d...P/html/sp_programming_pocket_pc_2002_balr.asp
Thankyou but I have already read this, and the above listing is a section of my autorun.exe application. This does not answer the problem I have documented above but thanks for taking time to assist me.
Just to outline, the problem that I am witnessing is that all the CAB files are being opened before the previous CAB installation has completed and the device is being warm booted without all the CAB files being installed. I need to wait in the looping code until a CAB file has completed its installation. The waitforsingleobject call should do this but it appears to fail. The CAB file has been opened succesfully but the error is that an invalid handle has been provided to the call. Thanks for any help
Doh! How stupid am I - please dont everyone reply. The programming error is in that I assign the return value of WaitForSingleObject to a variable. Change the above code snippet from
dwRetVal = WaitForSingleObject(info.hProcess, INFINITE);
to
WaitForSingleObject(info.hProcess, INFINITE);
and remove the switch..case code and it works fine.
Ok. So I now have my autorun.exe program that installs my CAB files but where do I put it in order for it to automatically install after a cold boot? I have tried the .EXE in "\storage card\2577" and in "\storage\2577" neither of them working. Modifying extended ROM is not an option here as this is a commercial package that is distributed on an SD card. I simply want the user to insert the SD card and then do a cold boot that will then install the CAB files. Is this possible and if so how? Thanks.
Got it all working now, the .EXE does go into the SD card subdirectory \storage card\2577.
HI,
Have you (or someOne else) tried to call registry keys (mostly interested in network connections) from this autorun.exe?
Herman
autorun?
what did you use for an autorun.exe??
is the code u put up earlier comilable to an autrun.exe?
(not a coder per se ,but dibble little here and there)
or is it from the sdk?
It it possible for u to post it as a attachment here?
Re: autorun?
lynxlynx said:
what did you use for an autorun.exe??
is the code u put up earlier comilable to an autrun.exe?
(not a coder per se ,but dibble little here and there)
or is it from the sdk?
It it possible for u to post it as a attachment here?
Click to expand...
Click to collapse
The Autorun.exe file can be whatever exe file you want.
that I understand...but what if I wanna install more than 1 thing...I have a list of stuff I wanna do...like a couple of .cab and some .exe´s and maybe a .cpf.....how can I get them all to run automatically on cardinsert....
I gave the code to a programmer at work..I will see what he comes upp with...but I thinkthat there should be somekind of "public" autrun.exe with a .cfg file with it to download here at xda-dev.
If mine works I will post it later...

[Q]Intent to launch a file manager

I've been banging my head on this, but can't seem to get it to work.
I'm trying to launch a file manager from my app. Here's the code I'm using.. I think (thought) it was correct, but I'm missing something. I want it to pop up a list of available file managers to open to that path.
Code:
Url = "file:///sdcard/";
Intent fileMangerIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Url));
startActivity(fileMangerIntent);
Thanks.
Edit: I've tried just passing /sdcard as the path, and also with and without the trailing slash. I've tried with an http url and it works as intended.
try using ACTION_CHOOSER, it should display all the activities on the phone that can handle that type of URI. http://developer.android.com/reference/android/content/Intent.html#ACTION_CHOOSER
Thanks.. I'll try that..
Doesn't seem to do what I'm trying to get it to do. If I specify a file and a mimetype (ie. a jpeg), then it works to popup a list of apps to view the file.
And with AndExplorer, I can have it popup as a file chooser or directory chooser.
But what i'm trying to is just launch a file explorer at the given path. Don't need any information back.
What I'm working on is an app that lists all attached usb drives (on HC Tablets) and allows mounting/unmounting any/all devices of ext, fat, ntfs. And I want to be able to click the mount points in my app to switch to a file explorer to browse the files.
But it doesn't seem like any of the file managers handle that. I might have to build in a minimal file manager.
If the file browsers you are trying to incorporate into your app dont support an entry point that takes you straight to a directory then it'll be hard to make this work. I guess the best you can do is look at the published intents and see if there is a way to pass a directory.
From something awesome

Help with this code..

Hi. I am following android tutorial in making audio player. This is my first app to learn. I'm just wondering if i can change the path location for the music/songs because in the code the path used is in the sdcard. I haven't a physical android phone I'm just using the virtual, I want to change it the location where my music on my laptop are place. Can i do that? how?
------------------------------this is the code----------------------------------------------------------
// SDCard Path
****final String MEDIA_PATH = new String("/sdcard/");
Thank you!
eebasadre20 said:
Hi. I am following android tutorial in making audio player. This is my first app to learn. I'm just wondering if i can change the path location for the music/songs because in the code the path used is in the sdcard. I haven't a physical android phone I'm just using the virtual, I want to change it the location where my music on my laptop are place. Can i do that? how?
------------------------------this is the code----------------------------------------------------------
// SDCard Path
****final String MEDIA_PATH = new String("/sdcard/");
Thank you!
Click to expand...
Click to collapse
When creating a new emulator, there is the option to use a folder as sdcard. In the app, I think you can just use the default /sdcard folder and it will be redirected to the hard drive folder by the emulator.

Trying to figure out directory structure bt-200

Hello I am trying to figure out how to write to file using the bt-200. I am using unity and c# to try and write an application for the glasses and I need to create and write to a txt file. I am using the line System.IO.File.WriteAllText (@"file.txt", data); to attempt this. What I cannot find is the proper path to use since I am unfamiliar with the devices directory structure. I have also tried to use path = System.IO.Directory.GetCurrentDirectory(); but this has not worked either and I cannot find the file I have supposedly generated. Any help would be appreciated.
Hi. There is a app on the bt-200 called "sev". Check the directory structure and your file with this app.
If your using windows, you should be aware that not every file is displayed, when you connect your bt-200 with your pc and use explore. Even if your are in the right folder.( That's why you need to recheck with sev)
The folder where you land, when you press explore in windows is "/mnt/sdcard"

Saving files to external storage, custom directory.

Hey all -
Have a question.
I want to call the Camera intent, but have the camera save to a custom file.
I've read this: https://developer.android.com/training/data-storage/files#WriteExternalStorage
And the only two options it gives is 'Save to a public directory" (like \Pictures, \Ringtones, etc), or "Save to a Provate Directory".
The latter sounds like it's what I want to do - but mentioned 'getExternalFilesDir()' function retrieves my application's custom data directory (which is (1)removed when the app is uninstalled, and (2)difficult to find when the phone is plugged into a computer - to copy the saved files from.)
What I'd REALLY wanna do is save my files to a root directory in the external storage. (Like, "/<sdcard mount path>/PicLogger/<file>").
Anyone know of a guide, or examples that show how to save images through the camera into a custom directory like this?
Thanks!
-Mike
You can save the file wherever you want, given that you have permission to write to SD card, by passing the file URI as MediaStore.EXTRA_OUTPUT in the MediaStore.ACTION_IMAGE_CAPTURE intent. See Save the full-size photo.
That being said, you should prefer something like "DCIM/YourAppName" or "Pictures/YourAppName", which apps like Google PhotoScan etc have been doing.
Code:
new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "YourAppName")
Apps should not create their own directories directly under the SD card root directory, and if they want to make something visible to user, it should be under one of the standard directories, preferrably under a subdirectory named after your app.
Or if you want to support scoped storage since Q, you can check out this SO answer.

Categories

Resources