1

This is the code. The application is installed successfully but in insertImage null is being stored always. i.e, the image is not getting stored in internal storage and always showing Drawing not saved!

final AlertDialog.Builder saveDialog = new AlertDialog.Builder(this);
    save.setOnClickListener(new View.OnClickListener(){

        @Override
        public void onClick(View view) {
            if (view.getId() == R.id.savebtn) {


                saveDialog.setTitle("Save Drawing");
                saveDialog.setMessage("Save drawing to Gallery");
                saveDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        drawableView.setDrawingCacheEnabled(true);
                        String insertImage = MediaStore.Images.Media.insertImage(MainActivity.this.getContentResolver(), drawableView.getDrawingCache(), UUID.randomUUID().toString() + ".png", "drawing");
                        if (insertImage!= null) {
                            Toast savedtoast = Toast.makeText(getApplicationContext(), "Drawing Saved to gallery!", Toast.LENGTH_SHORT);
                            savedtoast.show();
                        } else {
                            Toast unsaved = Toast.makeText(getApplicationContext(), "Drawing not saved!", Toast.LENGTH_SHORT);
                            unsaved.show();
                        }
                        drawableView.destroyDrawingCache();
                    }
                });
                saveDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.cancel();
                    }
                });
                saveDialog.show();
            }
        }
    });

Please help me out to recognize the problem.

Mihodi Lushan
  • 670
  • 5
  • 24
Anu Verma
  • 7
  • 4
  • please explain your problem in detail and be specific so that others can understand your problem, read your code, and help you. – Mihodi Lushan Aug 10 '20 at 19:39
  • I edited my query, please have a look now. – Anu Verma Aug 11 '20 at 07:22
  • can you please check or debug ```drawableView.getDrawingCache()```. this method is deprecated in API 28. check this is providing you the correct drawable. I think debugging that line with android studio debugger can help you. also check https://stackoverflow.com/a/17674787/5339146 https://stackoverflow.com/a/15662384/5339146 https://stackoverflow.com/a/38903796/5339146 for your understanding. – Mihodi Lushan Aug 11 '20 at 13:21
  • Does this answer your question? [Saving an image from ImageView into internal storage](https://stackoverflow.com/questions/38820673/saving-an-image-from-imageview-into-internal-storage) – Mihodi Lushan Aug 11 '20 at 13:24
  • https://appetize.io/app/4eet4ezthk0va9zg5dcqv8wg74?device=nexus5&scale=75&orientation=portrait&osVersion=8.1 – Anu Verma Aug 11 '20 at 14:52
  • this is my app. I want that when I click on save button, the image will save to gallery. But w.r.t above code in String insertImage always null stores. I hope you got it now what I am trying to say. – Anu Verma Aug 11 '20 at 14:54

0 Answers0