Here is my code: The file never gets created on the SDCARD
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
{
logger.info("There is no external SD card mounted...stopping application");
Toast.makeText(MonitorService.this, "There is no external SD card mounted...stopping application", Toast.LENGTH_SHORT).show();
return;
}
final File root = Environment.getExternalStorageDirectory();
final File binaryfile = new File(root, "test.log");
writer = new FileWriter(binaryfile, true);
out = new BufferedWriter(writer);
if (root.canWrite())
{
System.out.println("I do see this in the logs....");
out.write("This is a test");
out.write("\n");
out.close();
writer.close();
开发者_Python百科 }
The sdcard write only works if it is NOT mounted on the computer: is one of the devices automatically mounting the SD card? I've seen some of the vendor add-on services that automount the SD card. In general I'd expect root.canWrite()
to work correctly, but you may want to use getExternalStorageState to verify that the SD card is indeed available.
精彩评论