android-sdcard

How to create a directory in Android?

徘徊边缘 提交于 2019-12-01 04:09:50
问题 Everything is in the question. Here is my code : private void createDirectory(File currentDirectory) { File f = null; try { f = new File(currentDirectory.getCanonicalPath() + "/directory" + count); boolean success = f.mkdir(); if (!success) { Toast.makeText(currentContext, f.getName() + " could not be created", 15).show(); } } catch (IOException ioe) { Toast.makeText(currentContext, f.getName() + " could not be created", 15).show(); } count++; } I am writing a small file manager in Android

OutputStreamWriter does not append

孤者浪人 提交于 2019-12-01 03:55:01
Original code and its working saving the data to the SD Card // Writing data to internal storage btnSaveData.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isSDCardWritable()) { String dataToSave = etData.getText().toString(); try { // SD Card Storage File sdCard = Environment.getExternalStorageDirectory(); File directory = new File(sdCard.getAbsolutePath()+"/MyFiles"); directory.mkdirs(); File file = new File(directory, "text.txt"); FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter osw = new OutputStreamWriter(fos); // write the

How to check availability of space on external storage?

独自空忆成欢 提交于 2019-12-01 02:34:41
How do you check if the SD card is full or not so that your application can decide if it can continue to do its job i.e. write to external storage or notify the user that storage has run out of space. Jonik Watch out with StatFs & int overflow on newer devices The approach in this answer is broken on devices with large external storage . For example on my Nexus 7, it currently returns ~2 GB when in reality there is ~10 GB of space left. // DOES NOT WORK CORRECTLY ON DEVICES WITH LARGE STORAGE DUE TO INT OVERFLOW File externalStorageDir = Environment.getExternalStorageDirectory(); StatFs statFs

How to get sdcard(Secondary) storage path in android?

。_饼干妹妹 提交于 2019-12-01 01:29:51
I'm developing a File Manager app. I want show to the user the internal storage and the sdcard storage if it exists. For internal storage I use Environment.getExternalStorageDirectory().getPath() . How can I get the SD storage? not sure this solution fits a File Manager but after many years trying to get the right code, this is my most recent one: /** * Returns all available SD-Cards in the system (include emulated) * * Warning: Hack! Based on Android source code of version 4.3 (API 18) * Because there is no standard way to get it. * * @return paths to all available SD-Cards in the system

android get all external storage path for all devices

落花浮王杯 提交于 2019-12-01 01:23:15
getExternalStorageDirectory() return SD card path on my phone. ( Huawei Y320 - android 4.2.2 ). now, how to get path Phone Storage path for all devices and all API? loot at bottom screenshot. I'm using this method: public static final String SD_CARD = "sdCard"; public static final String EXTERNAL_SD_CARD = "externalSdCard"; private static final String ENV_SECONDARY_STORAGE = "SECONDARY_STORAGE"; public static Map<String, File> getAllStorageLocations() { Map<String, File> storageLocations = new HashMap<>(10); File sdCard = Environment.getExternalStorageDirectory(); storageLocations.put(SD_CARD,

OutputStreamWriter does not append

自作多情 提交于 2019-12-01 00:45:37
问题 Original code and its working saving the data to the SD Card // Writing data to internal storage btnSaveData.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isSDCardWritable()) { String dataToSave = etData.getText().toString(); try { // SD Card Storage File sdCard = Environment.getExternalStorageDirectory(); File directory = new File(sdCard.getAbsolutePath()+"/MyFiles"); directory.mkdirs(); File file = new File(directory, "text.txt");

Displaying images from specific folder in sd card in grid view

≡放荡痞女 提交于 2019-11-30 23:44:26
I had developed an application in which I have to display images from specific folder in sd card. My code is working fine but it is showing all images that are sd card. I had given selection args as my folder's name as it has been metioned the following post: Displaying images from a specific folder on the SDCard using a gridview But, it didn't worked. Please, suggest me how to do this: Below I am posting my code. public class Album1Activity extends Activity { static Cursor imageCursor; static int columnIndex; GridView gridView; Intent in; protected void onCreate(Bundle savedInstanceState) { /

How to check availability of space on external storage?

≡放荡痞女 提交于 2019-11-30 22:15:26
问题 How do you check if the SD card is full or not so that your application can decide if it can continue to do its job i.e. write to external storage or notify the user that storage has run out of space. 回答1: Watch out with StatFs & int overflow on newer devices The approach in this answer is broken on devices with large external storage . For example on my Nexus 7, it currently returns ~2 GB when in reality there is ~10 GB of space left. // DOES NOT WORK CORRECTLY ON DEVICES WITH LARGE STORAGE

can't create folder programmatically on external storage - Android

人走茶凉 提交于 2019-11-30 20:55:17
问题 This is my code: boolean success = false; Log.d(TAG, Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_PICTURES + "/myFolder" ); myFolder = new File( Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_PICTURES + "/myFolder" ); if( myFolder.exists() ){ Log.d(TAG, "FOLDER EXISTS"); }else{ success = myFolder.mkdir(); if( success ){ // Do something on success } else { // Do something else on failure throw new RuntimeException("File Error in writing new

WARNING: File.mkdir() is ignored

∥☆過路亽.° 提交于 2019-11-30 18:27:38
I've created a basic Audio Recording App using Media Recorder API's. I'm trying to create a folder in the SD card and to save my recorded files to that folder. I'm getting this warning with following code. File.mkdir() is ignored // Assign random number to avoid audio file from overwriting Long tsLong = System.currentTimeMillis()/1000; // Specify a Location for the recorded file to be stored in the SD card mFileName = Environment.getExternalStorageDirectory().getAbsolutePath() + "/AudioRecordTest/"; File path = new File(mFileName); if(!path.exists()) { path.mkdir(); } mFileName += "