Android: how to write a file to internal storage

Use the below code to write a file to internal storage: public void writeFileOnInternalStorage(Context mcoContext, String sFileName, String sBody){ File dir = new File(mcoContext.getFilesDir(), “mydir”); if(!dir.exists()){ dir.mkdir(); } try { File gpxfile = new File(dir, sFileName); FileWriter writer = new FileWriter(gpxfile); writer.append(sBody); writer.flush(); writer.close(); } catch (Exception e){ e.printStackTrace(); } } Starting in API 19, … Read more

Retrieve database or any other file from the Internal Storage using run-as

By design user build of Android (that’s what you have on your phone until you unlock the bootloader and flash the phone with userdebug or eng software) restricts access to the Internal Storage – every app can only access its own files. Fortunately for software developers not willing to root their phones Google provides a … Read more