1

I am using SquareCamera library (https://github.com/boxme/SquareCamera) for taking square picture.The problem I am facing is that SquareCamera is creating its own folder where taken pics are getting stored. I want these pics to store in my own folder. I don't know how to achieve that. I am very new to android. Below is the code where instead of default camera I am calling its own class.

public void onLaunchCamera(View view) {
    // create Intent to take a picture and return control to the calling application
    Intent intent = new Intent(this,CameraActivity.class);
    // Start the image capture intent to take photo
    startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); 

And this is the onActivityResult method

public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Uri takenPhotoUri = data.getData();
            Bitmap takenImage = BitmapFactory.decodeFile(takenPhotoUri.getPath());
            imageView.setImageBitmap(takenImage);

I thought about saving this bitmap into my own folder but I couldn't think how to delete the created directory of SquareCamera.

  • Seems like you want access to external storage. If I've not understood please explain. – John Oct 10 '15 at 11:55
  • Accessing external storage is not the issue. See I am using this library to take square pictures but this library is creating it's own folder name as SquareCamera in my phone I simply don't want this to happen I want my own created directory to store these pics. The issue is only the folder name I guess. – Sourabh Garg Oct 10 '15 at 12:02
  • See http://stackoverflow.com/a/26765884/5353361 for how to delete a folder in external storage. You will need the user's explicit consent post KK – John Oct 10 '15 at 12:05
  • Thanks. Going to check it. – Sourabh Garg Oct 10 '15 at 12:08
  • Feel free to hit the up button if you feel I've helped. – John Oct 10 '15 at 12:14

2 Answers2

1

So I found the solution. I added the library as a module in my app. Referring (https://www.youtube.com/watch?v=1MyBO9z7ojk). And there I changed the source code a little bit and now it's working perfect.

0

I'm a bit long in the tooth at Android and am not 100% with the new Uri methods of file access enforced since KitKat. For conventional file access you can get a private writeable file using.

private static final File OUTPUT_DIR = Environment.getExternalStorageDirectory();
FileOutputStream fos;

void yourMethodBeginsHere() {
    String outputPath = new File(OUTPUT_DIR, "test.png").toString();
    try {
        fos = new FileOutputStream(outputPath, false);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    //Work with file
}

If you need a truly external file path please refer to the excellent answer already existing at https://stackoverflow.com/a/26765884/5353361 which deals fully with the new Uri based system of permissions and the integrated file explorer.

Community
  • 1
  • 1
John
  • 6,433
  • 7
  • 47
  • 82
  • I can save the bitmap into my own folder using the files writable method. That won't be an issue. The problem here is how to restrict this library to create it's own folder and saving images there. What would be the workaround for that issue. – Sourabh Garg Oct 10 '15 at 11:55
  • Perhaps you could try the devlopers? – John Oct 10 '15 at 11:58
  • Yeah seem like the only choice. Although thanks for the help :) – Sourabh Garg Oct 10 '15 at 12:04