Reputation: 9317
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.
Upvotes: 3
Views: 16480
Reputation: 533
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.
Upvotes: 1
Reputation: 159
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.
Upvotes: 2
Reputation: 181
Does your request permission to write to the SD Card in the android manifest?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Upvotes: 18
Reputation: 47514
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
}
Upvotes: 6