4

I have a method in my activity that starts a image_capture event

    public static void takePhoto(boolean fullSize) {

    if(isIntentAvailable(mActivity.getApplicationContext(), MediaStore.ACTION_IMAGE_CAPTURE)){
        mActivity.startActivityForResult(new Intent(
                MediaStore.ACTION_IMAGE_CAPTURE), CAPTURE_IMAGE);
    }
    else{
        Toast.makeText(mActivity.getApplicationContext(), "Geen camera beschikbaar", Toast.LENGTH_SHORT).show();
    }
}

public static boolean isIntentAvailable(Context context, String action) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    List<ResolveInfo> list =
            packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
}

When the user has taken a picture, I want to get the bytes from the photo and broadcast those bytes.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_CANCELED) {

        case CAPTURE_IMAGE:
                byte[] photoBytes = null;

                if (data != null) {
                    Bitmap b = (Bitmap) data.getExtras().get("data");
                    ByteArrayOutputStream stream = new ByteArrayOutputStream();
                    b.compress(Bitmap.CompressFormat.PNG, 100, stream);
                    photoBytes = stream.toByteArray();

                    Toast.makeText(getApplicationContext(), "Foto wordt geupload..", Toast.LENGTH_SHORT).show();
                    Log.d("ShowScreenActivity", Integer.toString(photoBytes.length));

                    // Send bytearray back to server
                    BroadcastSender.sendPicture(photoBytes);
                }
                else
                    Log.d("ShowScreenActivity", "Data in intent is empty");

            break;
        }
    }
}

Everything works fine, but the image is also stored in the gallery on the device.
How can I prevent this or what do I do wrong?

Robby Smet
  • 4,649
  • 8
  • 61
  • 104
  • You can check [this link][1] [1]:http://marakana.com/forums/android/examples/39.html OR [Delete Photo after taken][2] [2]:http://stackoverflow.com/questions/6390163/deleting-a-gallery-image-after-camera-intent-photo-taken – Nikhil Sep 20 '12 at 11:35

2 Answers2

4

Your image is saved to the gallery, because that is the default behaviour. To override this, you need to specify a different target folder to save your image (in the intent calling the camera), and put a .nomedia file in the folder

njzk2
  • 38,969
  • 7
  • 69
  • 107
  • can you please specify the intent extra needed to store to a different directory? I'd love this solution if it works but cannot confirm that such an option exists. – Andrew G Oct 01 '12 at 18:51
  • use intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File("/sdcard/somefolder"))); when you invoke the camera – njzk2 Oct 02 '12 at 07:34
  • 2
    Using this write the image in the specified path yes, but still create an image also in the gallery. – Yoann Hercouet Sep 28 '13 at 06:42
  • @YoannHercouet : not if the path you specify contains a .nomedia file. – njzk2 Sep 28 '13 at 18:32
0

Do you store your picture temporarily in a directory in your sendPicture method of your BroadcastSender?

If the image is stored in a directory indexed by the MediaScanner, it would be automatically added to the gallery.

L. G.
  • 9,642
  • 7
  • 56
  • 78