List of usage examples for android.os Environment DIRECTORY_DOCUMENTS
String DIRECTORY_DOCUMENTS
To view the source code for android.os Environment DIRECTORY_DOCUMENTS.
Click Source Link
From source file:org.chromium.latency.walt.MainActivity.java
public String saveLogToFile() { // Save to file to later fire an Intent.ACTION_SEND // This allows to either send the file as email attachment // or upload it to Drive. // The permissions for attachments are a mess, writing world readable files // is frowned upon, but deliberately giving permissions as part of the intent is // way too cumbersome. String fname = "qstep_log.txt"; // A reasonable world readable location,on many phones it's /storage/emulated/Documents // TODO: make this location configurable? File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS); File file = null;/* w ww . j ava 2s. c om*/ FileOutputStream outStream = null; Date now = new Date(); logger.log("Saving log to:\n" + path.getPath() + "/" + fname); logger.log("On: " + now.toString()); try { if (!path.exists()) { path.mkdirs(); } file = new File(path, fname); outStream = new FileOutputStream(file); outStream.write(logger.getLogText().getBytes()); outStream.close(); logger.log("Log saved"); } catch (Exception e) { e.printStackTrace(); logger.log("Exception:\n" + e.getMessage()); } return file.getPath(); }
From source file:jp.mau.twappremover.MainActivity.java
@SuppressLint("NewApi") private void writeOut(String str) { FileOutputStream fos = null;/*from w w w. j a v a 2 s . c om*/ File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "test.txt"); try { fos = new FileOutputStream(file); fos.write(str.getBytes()); } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) try { fos.close(); } catch (Exception e) { ; } } }