title: Android: How do I "properly" create a publicly readable file?
body: <p>My app must create files that can then be easily read/written/copied from a connected PC. I've read everything I can find, and tried everything recommended by online comments and the Android docs, but I just can't get it to work.</p>
  
  <p>I am successfully creating and writing to files. Using ADB's shell I can see the files are there, but from (for example) Windows I can see every file in the directory EXCEPT the ones I'm creating. Files copied to the Android device from (say) Windows are publicly visible. But files my apps create - even if in the exact same directory - are not. Since I know the files are there but visibility is selective, I presume this is a permissions problem.</p>
  
  <p>Digging more, I found Context.MODE_WORLD_READABLE and _WRITABLE but "This constant was deprecated in API level 17" so this approach is clearly not the way to go. I also tried File.setReadable and File.setWritable on the existing files but both fail and return false.</p>
  
  <p>Yes, the app has "android.permission.WRITE_EXTERNAL_STORAGE" (or it wouldn't be writing to the external storage). It can create the files, they're just not publicly visible.</p>
  
  <p>I haven't been able to find any file creation methods that have any provision for explicitly creating publicly-accessible files except for File and Context which have problems as noted above. It looks like there have been multiple ways to do this over the years but they've either been deprecated, don't work, or I'm not using them properly.</p>
  
  <p>So... what is the proper and supported way to create publicly-accessible files in Android's external storage? Thanks!</p>
  
  <p><em>Edit: Code added. Nothing fancy, just proof of concept stuff at the moment. Again, this DOES successfully create files on the Android in the specified directory... but those files are not visible to outside devices when connected via USB, either "as a camera" nor "as a media device". All other directories and files are visible to the external device, just not those created by my app.</em></p>
  
  <pre><code>if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
      filename = (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/test.txt");
  
      try {
          writer = new FileWriter(filename); // use a FileWriter since we're using a String
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      try {
          writer.write(filename);
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      try {
          writer.flush();
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      try {
          writer.close();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>