Save file to sd card?

by Tommy » Fri, 23 Apr 2010 02:03:37 GMT


Sponsored Links
 Hi,

I am trying to find the best way to save files to the phone. Basically
I have an XML file on a web server that I would like to be able to
save on the phone. Should I create a specific folder in my project to
save to and if so how do I save the file. Or should I make it to where
when you click the Save button it checks for an SD card and if there
is and SD card create a folder(if one isn't already there) and save
the file in the new folder or save it to the phone?

If someone could explain the most efficient way of saving files for my
app and how to save the file from the web server I would greatly
appreciate the insight. Any tutorial links would be awesome.

Thanks!!

--



Save file to sd card?

by ~ TreKing » Fri, 23 Apr 2010 02:52:44 GMT


 



You can't write to folders in your project. You app, however, has a
dedicated data folder you can read from and write to.



That's up to you, either way works. Though if the file is huge, the SD is a
better option.

 If someone could explain the most efficient way of saving files for my app

This is pretty standard Java IO stuff. Look at the Android documentation for
how to write to your app's data space and to the SD card, and Google around
for Java IO. That should be all you need.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
 http://sites.google.com/site/rezmobileapps/treking 

--


Sponsored Links


Save file to sd card?

by dipu » Fri, 23 Apr 2010 03:03:55 GMT


 I believe there is only one way to create files and directories it
must be in the sd card. There are two ways to save data in files a)
via SharedPreferences and b) save in sdcard. The only other way to
save data in the phone is in the database.

If you use SharedPreferences generally speaking the data is not
available to other apps. Also if your data in the XML file is large it
is better to save it in the sd card.
Developers are not following any standard(rather common sense) in
creating files and directories. Most developers, including some google
employees create app name directory in the root of sd card. I think
the best way is to create directory like this "/sdcard/
com.google.android.apps.listen". I have been doing like this "/sdcard/
com/myco/myapp" and I am going to change my practice :-).

You can use regular Java file API classes to create and access files.
You will have to make sure that you set user permission for writing
into the file in your manifest file. Other important thing is obtain
the root of the "/sdcard" using API calls and do not hard code it.

--dipu







>



Save file to sd card?

by Tommy » Fri, 23 Apr 2010 03:11:18 GMT


 Ok the files will be small so i'll save them to the app data folder. My next
question is where is that folder located and how to I go about saving a file
to it? Is there an easy way to just pass the URL for the xml file and have
it save or would I need to open a file reader read the file to another
document builder and then save it?

 

Thanks!

 

From: android-developers@googlegroups.com
[mailto:android-develop...@googlegroups.com] On Behalf Of ~ TreKing
Sent: Thursday, April 22, 2010 2:51 PM
To: android-developers@googlegroups.com
Subject: Re: [android-developers] Save file to sd card?

 




Should I create a specific folder in my project to save to and if so how do
I save the file.

 

You can't write to folders in your project. You app, however, has a
dedicated data folder you can read from and write to.

 

Or should I make it to where when you click the Save button it checks for an
SD card and if there is and SD card create a folder(if one isn't already
there) and save the file in the new folder or save it to the phone?

 

That's up to you, either way works. Though if the file is huge, the SD is a
better option.

 

If someone could explain the most efficient way of saving files for my app
and how to save the file from the web server I would greatly appreciate the
insight. Any tutorial links would be awesome.


This is pretty standard Java IO stuff. Look at the Android documentation for
how to write to your app's data space and to the SD card, and Google around
for Java IO. That should be all you need.


----------------------------------------------------------------------------
---------------------
TreKing - Chicago transit tracking app for Android-powered devices
 http://sites.google.com/site/rezmobileapps/treking 

--



Save file to sd card?

by Mark Murphy » Fri, 23 Apr 2010 03:19:08 GMT


 


Call getFilesDir() from your activity to get to the application-local
file storage area.


Java I/O works:

 http://exampledepot.com/taxonomy/term/164 


Neither. You will wind up with the file in memory, either via a URL:

 http://exampledepot.com/egs/java.net/ReadFromURL.html 

or via HttpClient:

 http://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.0.x/httpclient/src/examples/org/apache/http/examples/client/ClientWithResponseHandler.java 

Then, use Java I/O to save it to a file.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android 2.x Programming Books:  http://commonsware.com/books 

--



Save file to sd card?

by Tommy » Fri, 23 Apr 2010 04:05:25 GMT


 Thanks for all the input everyone! I'm going to mess with this and see what
happens. Hopefully I won't need any more assistance on this issue. Thanks
for everyone's time!

-----Original Message-----
From: android-developers@googlegroups.com
[mailto:android-develop...@googlegroups.com] On Behalf Of Mark Murphy
Sent: Thursday, April 22, 2010 3:17 PM
To: android-developers@googlegroups.com
Subject: Re: [android-developers] Save file to sd card?




Call getFilesDir() from your activity to get to the application-local
file storage area.


Java I/O works:

 http://exampledepot.com/taxonomy/term/164 


Neither. You will wind up with the file in memory, either via a URL:

 http://exampledepot.com/egs/java.net/ReadFromURL.html 

or via HttpClient:

 http://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.0.x/htt 
pclient/src/examples/org/apache/http/examples/client/ClientWithResponseHandl
er.java

Then, use Java I/O to save it to a file.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android 2.x Programming Books:  http://commonsware.com/books 

--



Save file to sd card?

by ~ TreKing » Fri, 23 Apr 2010 04:07:59 GMT


 



And my next question is did you read the official documentation on this
subject? Because everything you need to know is right there.





Um, no. You can save any file to your app's local storage space, as I
mentioned before, and as Mark elaborated on in his post. IOW, you can save
XML, HTML, text, or whatever to your app's local storage space using
standard Java IO.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
 http://sites.google.com/site/rezmobileapps/treking 

--



Save file to sd card?

by Tommy » Fri, 23 Apr 2010 04:14:11 GMT


 Yeah Marks post with the links answered all my questions. I looked at the
documentation I could find from a google search but it didn't really hit the
nail on the head or (more likely) didn't click in my head.

 

From: android-developers@googlegroups.com
[mailto:android-develop...@googlegroups.com] On Behalf Of ~ TreKing
Sent: Thursday, April 22, 2010 4:07 PM
To: android-developers@googlegroups.com
Subject: Re: [android-developers] Re: Save file to sd card?

 




My next question is where is that folder located and how to I go about
saving a file to it?

 

And my next question is did you read the official documentation on this
subject? Because everything you need to know is right there.

 




I believe there is only one way to create files and directories it must be
in the sd card. There are two ways to save data in files a) via
SharedPreferences and b) save in sdcard. The only other way to save data in
the phone is in the database.

 

Um, no. You can save any file to your app's local storage space, as I
mentioned before, and as Mark elaborated on in his post. IOW, you can save
XML, HTML, text, or whatever to your app's local storage space using
standard Java IO.

 

----------------------------------------------------------------------------
---------------------
TreKing - Chicago transit tracking app for Android-powered devices
 http://sites.google.com/site/rezmobileapps/treking 

--



Other Threads

1. OOT : SA junior :)

Selamat atas kelahiran SA junior.

*Nama belum decide,yg katanya kemungkinan mau pake nama tio.pinghehehe ;) 
*canda*

Telah lahir pagi ini pada pukul : 7.15
Berat : 2730 mg 
Panjang : 50 cm
Jenis kelamin : laki2.
Rs : hermina podomoro.

Sekali lagi,saya dan keluarga mengucapkan selamat atas kelahiran putra juragan 
SA :)
Semoga menjadi anak yg berguna bagi bangsa dan negara. 
Once again CONGRATZZ brader..

Salam.
Tio.ping

PING'S mobile
plaza semanggi || lt 2B 149
: i...@pings-mobile.com

-- 
===============
"

2. [OOT] Mau Tanya ttg live streaming SMART

Mumpung lagi bahas SMART, kenapa saya nggak bisa dapat live streaming radio 
Hard Rock FM Jakarta tapi saya bisa live streaming dengan radio KIFM di San 
Diego sana kalau pakai SMART. Sudah pernah complain ke Gallery beberapa bulan 
yang lalu tapi nggak selesai masalahnya.

PJW

-- 
===============
"

3. Sony Ericsson ZEUS - Z1-PlayStation Phone

4. Problem Pada Router SGS Wifi

5. WTH : Front Facing Camera tidak aktif...

6. How do you hide a ListView on button press/click?

7. How to deploy and display images in App