cloud
cloud

Reputation: 77

How to save image into a main gallery?

I am trying to make a barcode generator with a library. The picture doesn't save into the main gallery. I don't want to save it into QRCode folder where I can find it only through File Manager.

I searched a lot but I cannot understand them.

I am a beginner that I would appreciate it if you explain it easily.

Many Thanks!

public class MainActivity extends AppCompatActivity {

    private String savePath = Environment.getExternalStorageDirectory().getPath() + "/QRCode/";
}
/**Barcode save*/
        findViewById(R.id.save_barcode).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
                    try {
                        boolean save = new QRGSaver().save(savePath, edtValue.getText().toString().trim(), bitmap, QRGContents.ImageType.IMAGE_JPEG);
                        String result = save ? "Image Saved" : "Image Not Saved";
                        Toast.makeText(activity, result, Toast.LENGTH_LONG).show();
                        edtValue.setText(null);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
                }
            }
        });
    }
}

Upvotes: 0

Views: 101

Answers (1)

Nadim Ansari
Nadim Ansari

Reputation: 574

If you have folder of QRCode and But you want to save your image to Camera Folder then you have to make folder like this :

File dir = new File( Environment.getExternalStoragePublicDirectory(
  Environment.DIRECTORY_DCIM), "Camera");

Updated as per Comment

Change your path like below code :

private String savePath = 
  Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_DCIM) + "/Camera/"

Upvotes: 2

Related Questions