3

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....

prasad.gai
  • 2,977
  • 10
  • 58
  • 93
  • I had a similiar problem this week and it turned out I had to manually define the external location by appending "/external_sd" to the getExternalStorage() for the galaxy tab, I can't find the article where I read that though sorry! – tutts Jul 06 '12 at 13:20
  • if not possible please vote on it.... – prasad.gai Jul 07 '12 at 03:13

2 Answers2

1

Take a look at the answer from this question, especially the one from Baron

Community
  • 1
  • 1
Yahel
  • 8,522
  • 2
  • 24
  • 32
1

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.

David Wasser
  • 93,459
  • 16
  • 209
  • 274