I am developing a program that need read/write some files from sdcard or internal storage at runtime. When I mount the sdcard in my phone it run correctly but if i unmount sdcard my application raises some error.
What I have to do for phones that have not card slot like Htc one x or phones that have not any sdcard inserted? how i can write on those phones storage? I don’t want write this file into /data/data/my.app.package folder. I want write somewhere that files can be read from another apps.
first I check storage status with this code and if sdcard be inserted and writable i have not any problem. but if sdcard does not exists i realy don’t know what i have to do.
string _location;
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
_location=Environment.getExternalStorageDirectory()+"/myfolder/";
Toast.makeText(context, _location, 1000).show();
}
else
{
_location="/myfolder/"
Toast.makeText(context, Environment.getExternalStorageDirectory().toString(), 1000).show();
}
mysync mys=new mysync(); // Asynctasc that writes some file on _location path
mys.execute(_location);
i am so confused and undortunately i haven’t any phone with big internal storage. please help me.
Here, and in your question title, you say you want to write to internal storage. Later, you say that you do not want to write to internal storage.
Which is it?
External storage != “sdcard”. External storage can be whatever the device manufacturer wants, so long as it meets the terms of the Compatibility Definition Document. Hence, external storage can be removable (e.g., SD card) or not (e.g.,. dedicated portion of on-board flash). And, on Android 3.0+, external storage is merely a special subdirectory on the same partition that contains internal storage.
You only care about whether external storage is presently available or not. It should be available pretty much all of the time on Android 3.0+ devices. It will be unavailable on Android 1.x and 2.x devices if the device is plugged into a host computer and the host computer has mounted the device’s external storage (e.g., as a drive letter on Windows).
You ask the user to please unmount their device from their host computer. Or, you decide to write to internal storage in those cases.