I made an drawing application in android studio. how can I save the drawing in the internal storage and view it afterwards in another activity? I've got some codes in the internet on how to save the bitmap but it won't work and I don't what I've done wrong. I am already stuck in this part.
Here are some of the codes:
public onClick(View v){
if(v.getId() == R.id.btnBrush){
.....
}
else if(v.getId() == R.id.btnErase){
.....
}
else if(v.getId() == R.id.ibtnSave){
//save button clicked
final Dialog saveDialog = new Dialog(this);
saveDialog.setTitle("Save");
saveDialog.setContentView(R.layout.save_form);
saveDialog.show();
inputName = (EditText) findViewById(R.id.drawFile);
inputDate = (EditText) findViewById(R.id.date);
btnSave = (Button) saveDialog.findViewById(R.id.btnSave);
btnCancel = (Button) saveDialog.findViewById(R.id.btnCancel);
btnSave.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
iView.setDrawingCacheEnabled(true);
save();
saveDialog.dismiss();
Intent intent = new Intent(DrawingPanel.this, Gallery.class);
startActivity(intent);
finish();
iView.destroyDrawingCache();
}
});
btnCancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
saveDialog.dismiss();
}
});
}
}
public void save(){
Bitmap bitmap = iView.getDrawingCache();
try{
FileOutputStream fos = openFileOutput(inputName.getText().toString() + ".png", Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
if(fos != null){
Toast saved = Toast.makeText(getApplicationContext(), "Image saved.", Toast.LENGTH_SHORT);
saved.show();
}
else{
Toast unsaved = Toast.makeText(getApplicationContext(), "Image not save.", Toast.LENGTH_SHORT);
unsaved.show();
}
fos.close();
}
catch(Exception e){
Log.e("save()", e.getMessage());
}
}
I want to add the date on it as well but I just don't know how to do it. I am really sorry guys. I'm just new in android studio and I am not really good at this that's why I need help cause I really want to learn.