1

I need help on a tricky issue. I write an app that shall work with a file being provided on the SD card - manipulates this file - and writes it back to the SD card. So far so good. Everything is working fine within the Eclipse environment with SD emulation. As soon as I install the app on my Sony Xperia - the app does not find the file on the SD card - nor can I find files/dirs which I store/create on the SD card. I am issuing the test-app I wrote for the Sony and kindly ask you for help on this issue!

Here is the code snippet of the app - trying to create a directory:

public class IOTestActivity extends ActionBarActivity {

private boolean mExternalStorageAvailable;
private boolean mExternalStorageWriteable;

TextView debugInfo;
TextView availInfo;
TextView writeInfo;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_iotest);

    debugInfo = (TextView)findViewById(R.id.iotestLbLDebugInfo);
    checkSDCard();
    fillView();
    readSDCard();
}


private void readSDCard() {

    debugInfo.append("...start reading SD dirs\n\n");
    if ((mExternalStorageAvailable==true) &&
            (mExternalStorageWriteable == true)) {

        File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        debugInfo.append("SD-Root='" + root + "'\n");

        File newDir = new File (root, "TEST");
        boolean result = newDir.mkdir();
        debugInfo.append("...creating new dir '" + newDir + "' = " + result);
    }       
}


private void fillView() {

    debugInfo.setText("...entering IO Test\n");
    debugInfo.append("...reading SD-card availability\n");

    availInfo = (TextView)findViewById(R.id.iotestLblInfo1);
    availInfo.setText("" + mExternalStorageAvailable);

    debugInfo.append("...reading SD-card writing rights\n");

    writeInfo = (TextView)findViewById(R.id.iotestLblInfo2);
    writeInfo.setText("" + mExternalStorageWriteable);

}


private void checkSDCard() {
    String state = Environment.getExternalStorageState();

    if (Environment.MEDIA_MOUNTED.equals(state)) {
        // Can read and write the media
        mExternalStorageAvailable = mExternalStorageWriteable = true;
    } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
        // Can only read the media
        mExternalStorageAvailable = true;
        mExternalStorageWriteable = false;
    } else {
        // Can't read or write
        mExternalStorageAvailable = mExternalStorageWriteable = false;
    }   
}
  }

Of course I have added to my Manifest.xml:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >

Here ist the test-output of the app:

BTW: the problem exists independent from the fact if I use:

File root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

or

File root = Environment.getExternalStorageDirectory();

And when I access the SD-card via USB-connected phone through the file explorer, I always receive the same contents of the SD card:

Thanks for help!

prakash
  • 1,413
  • 1
  • 21
  • 33
  • Check this : http://stackoverflow.com/questions/13976982/removable-storage-external-sdcard-path-by-manufacturers – VVB Jul 24 '14 at 06:34

0 Answers0