Saving Logcat to a text file in Android Device

Use an Application class at the beginning of your app. That allows a proper file and log handling. Code below creates a log file at the following location: /ExternalStorage/MyPersonalAppFolder/logs/logcat_XXX.txt XXX is the current time in milliseconds. Every time you run your app, a new logcat_XXX.txt file will be created. public class MyPersonalApp extends Application { … Read more

Writing Text File to SD Card fails

You can use this method to check de sdCard state. Change the toast dialog to you language: ** Care with MEDIA_MOUNTED_READ_ONLY. In no need write in the SDCard and i return true ** public static Boolean comprobarSDCard(Context mContext) { String auxSDCardStatus = Environment.getExternalStorageState(); if (auxSDCardStatus.equals(Environment.MEDIA_MOUNTED)) return true; else if (auxSDCardStatus.equals(Environment.MEDIA_MOUNTED_READ_ONLY)) { Toast.makeText( mContext, “Warning, the … Read more

Copying raw file into SDCard?

Read from the resource, write to a file on the SD card: InputStream in = getResources().openRawResource(R.raw.myresource); FileOutputStream out = new FileOutputStream(somePathOnSdCard); byte[] buff = new byte[1024]; int read = 0; try { while ((read = in.read(buff)) > 0) { out.write(buff, 0, read); } } finally { in.close(); out.close(); }

Android SD Card Write Permission using SAF (Storage Access Framework)

Letting the user choose the “SD card” or even the “Internal storage” SAF root give your application access to the corresponding storage, but only through the SAF API, not directly via the filesystem. For example you code could be translated into something like : public void writeFile(DocumentFile pickedDir) { try { DocumentFile file = pickedDir.createFile(“image/jpeg”, … Read more

Android Open External Storage directory(sdcard) for storing file

I had been having the exact same problem! To get the internal SD card you can use String extStore = System.getenv(“EXTERNAL_STORAGE”); File f_exts = new File(extStore); To get the external SD card you can use String secStore = System.getenv(“SECONDARY_STORAGE”); File f_secs = new File(secStore); On running the code extStore = “/storage/emulated/legacy” secStore = “/storage/extSdCarcd” works … Read more