I am using an custom view and in that i am using an canvas in which a user can draw anything and after that i want to save that image in sd card bt was not able to do that. Don't know what is going on.
else if(view.getId()==R.id.save_btn){
//save drawing
AlertDialog.Builder saveDialog = new AlertDialog.Builder(this);
saveDialog.setTitle("Save drawing");
saveDialog.setMessage("Save drawing to device Gallery?");
saveDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
private FileOutputStream fOut;
public void onClick(DialogInterface dialog, int which){
//save drawing
drawView.setDrawingCacheEnabled(true);
//attempt to save
String imgSaved = MediaStore.Images.Media.insertImage(
getContentResolver(), drawView.getDrawingCache(),
UUID.randomUUID().toString()+".png", "drawing");
//feedback
if(imgSaved!=null){
Toast savedToast = Toast.makeText(getApplicationContext(),
"Drawing saved to Gallery!", Toast.LENGTH_SHORT);
savedToast.show();
}
else{
Toast unsavedToast = Toast.makeText(getApplicationContext(),
"Oops! Image could not be saved.", Toast.LENGTH_SHORT);
unsavedToast.show();
}
drawView.destroyDrawingCache();
}
});
saveDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
dialog.cancel();
}
});
saveDialog.show();
}
HERE IS THE ERROR DETAILS
04-14 11:24:28.700: E/MediaStore(6866): Failed to insert image
04-14 11:24:28.700: E/MediaStore(6866): java.io.FileNotFoundException: No such file or directory
04-14 11:24:28.700: E/MediaStore(6866): at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:146)
04-14 11:24:28.700: E/MediaStore(6866): at android.content.ContentProviderProxy.openAssetFile(ContentProviderNative.java:577)
04-14 11:24:28.700: E/MediaStore(6866): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:673)
04-14 11:24:28.700: E/MediaStore(6866): at android.content.ContentResolver.openOutputStream(ContentResolver.java:537)
04-14 11:24:28.700: E/MediaStore(6866): at android.content.ContentResolver.openOutputStream(ContentResolver.java:513)
04-14 11:24:28.700: E/MediaStore(6866): at android.provider.MediaStore$Images$Media.insertImage(MediaStore.java:891)
04-14 11:24:28.700: E/MediaStore(6866): at com.example.clent.MainActivity$9.onClick(MainActivity.java:238)
04-14 11:24:28.700: E/MediaStore(6866): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
04-14 11:24:28.700: E/MediaStore(6866): at android.os.Handler.dispatchMessage(Handler.java:99)
04-14 11:24:28.700: E/MediaStore(6866): at android.os.Looper.loop(Looper.java:137)
04-14 11:24:28.700: E/MediaStore(6866): at android.app.ActivityThread.main(ActivityThread.java:5103)
04-14 11:24:28.700: E/MediaStore(6866): at java.lang.reflect.Method.invokeNative(Native Method)
04-14 11:24:28.700: E/MediaStore(6866): at java.lang.reflect.Method.invoke(Method.java:525)
04-14 11:24:28.700: E/MediaStore(6866): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
04-14 11:24:28.700: E/MediaStore(6866): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-14 11:24:28.700: E/MediaStore(6866): at dalvik.system.NativeStart.main(Native Method)
I am always getting this message while trying to save image...."Oops! Image could not be saved.".....
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…