2

As the title states, I'm trying to launch the camera and take a picture that I can use with the APP locally. This is for the Motorola Xoom and, by default, they do not come with SD cards. Or at least the ones my client is looking into purchasing do not have SD cards.

I've found a pretty nice tutorial on how to launch the camera and I can get it to launch and everything up to it physically saving the image and then being able to re-use that image.

A lot of the solutions or other tutorials I've found only show how to save to an SD card -- not to resident memory or local to the app. It looks like it is possible to do so but am stumped. :-/

3 Answers3

2

You could perhaps load it to ContentProvider so that you could use the images later for anything:

// Add some parameters to the image that will be stored in the Image ContentProvider
int UNIQUE_BUCKET_ID = 1337;
ContentValues values = new ContentValues(7);
values.put(MediaStore.Images.Media.DISPLAY_NAME,"name of the picture");
values.put(MediaStore.Images.Media.TITLE,"Thats the title of the image");
values.put(MediaStore.Images.Media.DESCRIPTION, "Some description");
values.put(MediaStore.Images.Media.BUCKET_DISPLAY_NAME,"Album name"); 
values.put(MediaStore.Images.Media.BUCKET_ID,UNIQUE_BUCKET_ID);
values.put(MediaStore.Images.Media.DATE_TAKEN,System.currentTimeMillis());
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");

// Inserting the image meta data inside the content provider
Uri uri = getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);

// Filling the real data returned by the picture callback function into the content provider
try {
    OutputStream outStream = getContentResolver().openOutputStream(uri);
    outStream.write(buffer);  // buffer is the data stream returned by the picture callback
    outStream.close();
}catch (Exception e) {
    Log.e(TAG, "Exception while writing image", e);
}
Ian
  • 3,500
  • 1
  • 24
  • 25
0

Check out Activity.getFilesDir() and Activity.getCacheDir() they provide access to storage where the app is stored. Also check out Environment.getExternalStoragePublicDirectory (), external, here, means outside the application's private directories. There are several others so look around the API's similarly named methods to find the best fit for you.

Dan S
  • 9,139
  • 3
  • 37
  • 48
0

So one thing you should note is that when you call Environment.getExternalStorageDirectory(), this does not necessarily correspond to an external memory space (i.e. and SD card) and would return a local memory space on devices without SD card slots.

Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

http://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()

The same applies for Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);

Rajiv Makhijani
  • 3,631
  • 32
  • 31