tags:

views:

2487

answers:

5

Hi,

In my MediaPlayer application for streaming Video i am using the following code

File temp = File.createTempFile("mediaplayertmp", "dat");

while running it throws exceptions like

Parent directory of file in not 
writable:/sdcard/
mediaplayertmp43912.dat

I dont how to handle this problem,and i want to know that when we execute that code means where the file will be created.any one knows the solution means please help with some code.

+4  A: 

I'm not sure what you're wanting to do... if the directory isn't writable it isn't writable. Throw an error for the user telling them that their SDCard needs write permission (possibly with instructions on how to fix).

In a couple of apps I have code similar to like this to make sure there is an SDCard... shouldn't be difficult to modify it to make sure it's also writable:

// make sure we have a mounted SDCard
if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
 // they don't have an SDCard, give them an error message and quit
 final AlertDialog.Builder builder = new AlertDialog.Builder(this);
 builder.setMessage(R.string.welcome_dialog_sdcard_error)
  .setCancelable(false)
  .setPositiveButton(R.string.welcome_dialog_sdcard_ok, new DialogInterface.OnClickListener() {
   public void onClick(final DialogInterface dialog, final int id) {
    finish();
   }
  });
 final AlertDialog alert = builder.create();
 alert.show();
} else {
 // there's an SDCard available, continue
}
fiXedd
+6  A: 

Does your request permission to write to the SD Card in the android manifest?

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
SandyK
+1  A: 

I had this same issue. My app was working fine until I updated the SDK. It now requires the WRITE_EXTERNAL_STORAGE permission to write to the SD Card.

man910
A: 

Don't mount your SD card while you are testing your app ^^

cloudolphin
A: 

The code works as-is in Android 1.5 or earlier. Anything more recent requires the app to specifically ask for WRITE_EXTERNAL_STORAGE permission in its manifest.

Cross_