Search code examples
androidfilesaveexternalsd-card

How to save file on external SDCARD on android MotorolaARTIX2 device?


I would like to save a file on external SdCard.I have implemented an application for save a file on external sdcard.But my Android MotorolaARTIX2 device contains internal sdcard.When i am trying to save file on external sdcard it always saving to internal sdcard in my device.

I have implemented my application as follows:

     try {
        File root = Environment.getExternalStorageDirectory();
        if (root.canWrite()){
            File file = new File(root, "myfile.txt");
            FileWriter gpxwriter = new FileWriter(file);
            BufferedWriter out = new BufferedWriter(gpxwriter);
            out.write("Hello world");
            out.close();
        }
    } catch (IOException e) {
        Log.e("Exception", "Could not write file " + e.getMessage());
    }

From the above code my application always saving myfile.txt file on internal sdcard but not external sdcard-ext.And my application is support all devices with same code.

How can i save myfile.txt on sdcard-ext(external) not on sdcard(internal) in my device?

please any body help me....


Solution

  • Motorola has an API for this. Look here: http://developer.motorola.com/docs/motorola-external-storage-api/ But that's not a good generic solution. You probably need to scan the filesystem for a more generic solution that will work on all devices.