title: Writing to logfile does not work with Android 4.2 Jelly Bean
body: <p>I am trying to integrate some code for a school project that takes sensor values received over bluetooth and write them to a comma separated data log file. I can not get a simple example of the file writing functionality running on Jelly Bean after trying dozens of examples. The code works perfectly fine on my personal device running android 4.0.2. I am trying to run the following example on a motorolla xt1060, and although there is no removable sd card, my understanding is that this does not preclude the use of external storage. I've used both linux with MTPFS and windows with the default drivers to look for the file anywhere on the file-system but it has never shown itself. I can see text files when I create them with the MTPFS mounted via terminal and when I take pictures so I don't think MTP is causing the problem. </p>
  
  <p>Here is the most simple java example I've written that works on 4.0 and not 4.2:</p>
  
  <pre><code>import java.io.BufferedWriter;
  import java.io.File;
  import java.io.FileWriter;
  import java.io.IOException;
  import android.app.Activity;
  import android.os.Bundle;
  import android.os.Environment;
  import android.util.Log;
  
  public class MainActivity extends Activity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
          path.mkdirs();
          File file = new File(path, "test.txt");
          Log.d("FILE_TEST", file.getPath());
  
          try {
              Log.d("FILE_TEST", "Creating buffer");
              BufferedWriter buf = new BufferedWriter(new FileWriter(file));
              Log.d("FILE_TEST", "Writing to buffer");
              buf.write("Hello FS!\n");
              Log.d("FILE_TEST", "Flushing buffer");
              buf.flush();
              Log.d("FILE_TEST", "Closing file");
              buf.close();
          } catch (IOException e) {
              Log.d("FILE_TEST","Caught Exception:" + e.toString());
          }
      }
  }
  </code></pre>
  
  <p>The manifest xml contains the following:</p>
  
  <pre><code>   &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
  </code></pre>
  
  <p>And nothing exciting I can see happens in the log:</p>
  
  <pre><code>02-18 00:26:36.075: I/InputReader(859): Reconfiguring input devices.  changes=0x00000004
  02-18 00:26:36.075: I/InputReader(859): Device reconfigured: id=6, name='synaptics_dsx_i2c', size 720x1280, orientation 3, mode 1, display id 0
  02-18 00:26:36.533: I/SurfaceFlinger(290): triggers:    (post: 0:16)    (compose: 0:2)  (frame: 0:12)   (gap: 411:6519) (rate: 247) (66116 frames)
  02-18 00:26:36.561: I/SurfaceFlinger(290): triggers:    (jitter: 0:0)   (missed: 0) (105353 vsyncs)
  02-18 00:26:37.045: I/ActivityManager(859): Config changes=480 {1.0 311mcc480mnc en_US ldltr sw360dp w360dp h567dp 320dpi nrml port finger -keyb/v/h -nav/h s.23?spn}
  02-18 00:26:37.051: I/InputReader(859): Reconfiguring input devices.  changes=0x00000004
  02-18 00:26:37.051: I/InputReader(859): Device reconfigured: id=6, name='synaptics_dsx_i2c', size 720x1280, orientation 0, mode 1, display id 0
  02-18 00:26:37.101: W/ContextImpl(1155): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1115 android.content.ContextWrapper.sendBroadcast:338 com.motorola.motocare.util.TriggerHelper$TriggerBuilder.send:76 com.motorola.motocare.internal.frameworkevents.PauseResumeTrigger.handleFrameworkEvent:53 com.motorola.motocare.internal.frameworkevents.FwEventMonitor$FrameworkListener.processFrameworkEvent:114 
  02-18 00:26:37.124: I/SurfaceFlinger(290): triggers:    (post: 0:16)    (compose: 0:2)  (frame: 0:12)   (gap: 411:6520) (rate: 247) (66124 frames)
  02-18 00:26:37.127: D/FILE_TEST(19084): /storage/emulated/0/Download/test.txt
  02-18 00:26:37.127: D/FILE_TEST(19084): Creating buffer
  02-18 00:26:37.127: D/FILE_TEST(19084): Writing to buffer
  02-18 00:26:37.127: D/FILE_TEST(19084): Flushing buffer
  02-18 00:26:37.127: D/FILE_TEST(19084): Closing file
  02-18 00:26:37.186: I/SBar.NetworkController(1008): onReceive: Intent.ACTION_CONFIGURATION_CHANGED Received
  02-18 00:26:37.186: I/SBar.NetworkController(1008): updateTelephonySignalStrength:  No service
  02-18 00:26:37.290: I/SurfaceFlinger(290): triggers:    (post: 0:16)    (compose: 0:2)  (frame: 0:12)   (gap: 411:6522) (rate: 247) (66132 frames)
  02-18 00:26:37.718: I/SurfaceFlinger(290): triggers:    (post: 0:16)    (compose: 0:2)  (frame: 0:12)   (gap: 411:6522) (rate: 247) (66159 frames)
  02-18 00:26:37.743: I/InputReader(859): Reconfiguring input devices.  changes=0x00000004
  02-18 00:26:37.743: I/InputReader(859): Device reconfigured: id=6, name='synaptics_dsx_i2c', size 720x1280, orientation 1, mode 1, display id 0
  02-18 00:26:37.744: I/ActivityManager(859): Config changes=480 {1.0 311mcc480mnc en_US ldltr sw360dp w598dp h335dp 320dpi nrml land finger -keyb/v/h -nav/h s.24?spn}
  02-18 00:26:37.776: W/ContextImpl(1155): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1115 android.content.ContextWrapper.sendBroadcast:338 com.motorola.motocare.util.TriggerHelper$TriggerBuilder.send:76 com.motorola.motocare.internal.frameworkevents.PauseResumeTrigger.handleFrameworkEvent:53 com.motorola.motocare.internal.frameworkevents.FwEventMonitor$FrameworkListener.processFrameworkEvent:114 
  02-18 00:26:37.817: I/SurfaceFlinger(290): triggers:    (post: 0:16)    (compose: 0:2)  (frame: 0:12)   (gap: 411:6523) (rate: 247) (66164 frames)
  02-18 00:26:37.829: I/SurfaceFlinger(290): triggers:    (jitter: 0:0)   (missed: 0) (105404 vsyncs)
  </code></pre>
  
  <p>Does anyone have an idea why this would work on 4.0 and not 4.2?</p>