0

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.

1

2 Answers 2

0

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

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.